表示整数的高2字节和低2字节 本帖最后由 xiadun 于 2014-01-02 14:52:32 编辑 有一个32位整数如:65606 如何表示它的高2字节和低2字节 [解决办法] unsigned int a = 56505; unsigned short int b = (a >> 16) & 0xffff; //高2字节 unsigned short int c = a & 0xffff; //低2字节
[解决办法]
unsigned int a = 56505; unsigned short int b = *((unsigned short*)&a); //高2字节 unsigned short int c = *(((unsigned short*)&a) + 1); //高2字节 [解决办法]
int i=65606; printf("%04X %04X",((unsigned short *)&i)[1],((unsigned short *)&i)[0]);//小端内存 printf("%04X %04X",((unsigned short *)&i)[0],((unsigned short *)&i)[1]);//大端内存
[解决办法]
unsigned int a = 56505; unsigned short int b = (a >> 16) & 0xffff; //高2字节 unsigned short int c = a & 0xffff; //低2字节
有一个32位整数如:65606 如何表示它的高2字节和低2字节
++
地址要分大小端 简单的移位运算,就不需要了分大小端。 平台自己会处理好这个问题的。
[解决办法]
union { int32_t int_member; uint8_t char_member[4]; }