天道酬勤,学无止境

endianness

Little-Endianness 在 x86 架构中是字节顺序还是位顺序?(Is Little-Endianness a byte order or a bit order in the x86 architecture?)

问题 标题说明了一切。 我想知道从内存读取数据的 x86 指令是否将其字节或位转换为 Little-Endian 顺序。 例如,如果我们在地址 0(二进制)(此处以 RAW 格式,顺序写入)有以下数据: 00110010 01010100 我们通过以下方式阅读它: mov ax, word [0] AX将包含什么 - “01010100 00110010”或“00101010 01001100”? 或者翻译成十进制的无符号整数——“21554”或“10828”? 我想 x86 整数指令会将寄存器顺序二进制数据解释为 Big-Endian 二进制数,与写入阿拉伯数字的字节顺序相同。 回答1 1.3.1 位和字节顺序 x86 是小端的。 在内存中的数据结构的插图中,较小的地址出现在图的底部; 地址向顶部增加。 位位置从右到左编号。 设置位的数值等于 2 的位位置的幂。 IA-32 处理器是“小端”机器; 这意味着一个字的字节从最低有效字节开始编号。 图 1-1 说明了这些约定。 术语字节序和字节序是指当这些字节存储在计算机内存中时用于解释构成数据字的字节的约定。 在计算中,内存通常通过将二进制数据组织成称为字节的 8 位单元来存储二进制数据。 当读取或写入由多个这样的单元组成的数据字时,内存中存储的字节顺序决定了数据字的解释。 内存中的每个字节数据都有自己的地址。

2021-11-28 16:53:55    分类:技术分享    assembly   x86   cpu   endianness

Why does an 8-bit field have endianness?

See the definition of TCP header in /netinet/tcp.h: struct tcphdr { u_int16_t th_sport; /* source port */ u_int16_t th_dport; /* destination port */ tcp_seq th_seq; /* sequence number */ tcp_seq th_ack; /* acknowledgement number */ # if __BYTE_ORDER == __LITTLE_ENDIAN u_int8_t th_x2:4; /* (unused) */ u_int8_t th_off:4; /* data offset */ # endif # if __BYTE_ORDER == __BIG_ENDIAN u_int8_t th_off:4; /* data offset */ u_int8_t th_x2:4; /* (unused) */ # endif u_int8_t th_flags; # define TH_FIN 0x01 # define TH_SYN 0x02 # define TH_RST 0x04 # define TH_PUSH 0x08 # define TH_ACK 0x10 # define TH_URG

2021-11-28 15:35:06    分类:问答    c   networking   interop   system   endianness

Details about Endian-ness and .Net?

I have a few questions about endian-ness that are related enough that I warrant putting them in as one question: 1) Is endian-ness decided by .Net or by the hardware? 2) If it's decided by the hardware, how can I figure out what endian the hardware is in C#? 3) Does endian-ness affect binary interactions such as ORs, ANDs, XORs, or shifts? I.E. Will shifting once to the right always shift off the least significant bit? 4) I doubt it, but is there a difference in endian-ness from different versions of the .Net framework? I assume they're all the same, but I've learned to stop assuming about

2021-11-28 11:56:16    分类:问答    c#   endianness

何时使用 hton/ntoh 以及何时自己转换数据?(when to use hton/ntoh and when to convert data myself?)

问题 要从另一台大端机器转换字节数组,我们可以使用: long long convert(unsigned char data[]) { long long res; res = 0; for( int i=0;i < DATA_SIZE; ++i) res = (res << 8) + data[i]; return res; } 如果另一台机器是小端的,我们可以使用 long long convert(unsigned char data[]) { long long res; res = 0; for( int i=DATA_SIZE-1;i >=0 ; --i) res = (res << 8) + data[i]; return res; } 为什么我们需要上述功能? 我们不应该在发件人处使用 hton 并在接收时使用 ntoh 吗? 是因为 hton/nton 是转换整数,而这个 convert() 是用于 char 数组吗? 回答1 hton / ntoh函数在网络顺序和主机顺序之间进行转换。 如果这两个相同(即在大端机器上),这些函数什么都不做。 因此,不能移植地依赖它们来交换字节序。 此外,正如您所指出的,它们仅针对 16 位( htons )和 32 位( htonl )整数定义; 您的代码最多可以处理sizeof(long long)具体取决于DATA

2021-11-28 02:05:53    分类:技术分享    endianness

Big endian or Little endian on net?

In what byte order does data transfer occur on net? Is it Little Endian or big endian? How is it converted to the respective byte order once the data reaches the host ?

2021-11-27 23:17:09    分类:问答    network-protocols   endianness

git svn rebase resulted in "byte order is not compatible" error

Following is the error I am getting when I tried 'git svn rebase': Byte order is not compatible at ../../lib/Storable.pm (autosplit into ../../lib/auto/Storable/_retrieve.al) line 380, at /usr/lib/perl5/5.10/Memoize/Storable.pm line 21 The version of perl I am running is: $ perl --version This is perl, v5.10.1 (*) built for i686-cygwin-thread-multi-64int (with 12 registered patches, see perl -V for more detail) When I searched the web for "Byte order is not compatible" and I get numerous hits that shows the Perl doc that says: What this means is that if you have data written by Storable 1.x

2021-11-27 15:43:31    分类:问答    perl   git-svn   compatibility   rebase   endianness

Is x86-64 machine language big endian?

0x0000000000400507 <main+28>: 74 0c je 0x400515 <main+42> 0x0000000000400509 <main+30>: bf 28 06 40 00 mov $0x400628,%edi .. 0x400507 <main+28>: 0x28bf0c74 I think shows the machine code is big-endian. Is my conclusion right?

2021-11-27 12:11:13    分类:问答    assembly   x86-64   endianness   machine-code

To big endian or to little endian? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago. let's say that we ignore the target and source hardware for a moment. So, what's the better endian style to go with -- big or small? I'm just trying to go with consensus / convention on this one. The best guidance I've received so far is

2021-11-26 16:02:46    分类:问答    c#   .net   c++   hardware   endianness

Endianness -- why do chars put in an Int16 print backwards?

The following C code, compiled and run in XCode: UInt16 chars = 'ab'; printf("\nchars: %2.2s", (char*)&chars); prints 'ba', rather than 'ab'. Why?

2021-11-26 07:44:16    分类:问答    c   xcode   char   endianness

苹果心率监测示例及蓝牙心率测量特性的字节序(Apple's heart rate monitoring example and byte order of bluetooth heart rate measurement characteristics)

问题 关于心率测量的特点: http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml 编辑 链接现在位于 https://www.bluetooth.com/specifications/gatt/characteristics/ 并查找“心率测量”。 它们不再提供 XML 查看器,而是您需要直接查看 XML。 对于服务,它也位于此页面上。 结束编辑 我想确保我正确阅读了它。 这实际上是说 5 个字段吗? 强制性的,C1、C2、C3 和 C4? 强制在第一个字节,C4在最后两个字节,C1和C2为8位字段,C3到C4各为16位。 总共有 8 个字节。 我是否正确阅读了这份文件? 编辑: 我被告知强制标志字段表示某物为 0,这意味着它不存在。 例如,如果第一位是 0,C1 是下一个字段,如果是 1,则 C2 跟随。 结束编辑 在 Apple 的 OSX 心率监测器示例中: - (void) updateWithHRMData:(NSData *)data { const uint8_t *reportData = [data bytes]; uint16_t

2021-11-26 00:40:03    分类:技术分享    bluetooth   bluetooth-lowenergy   endianness