unsigned int a = 56505;
unsigned short int b = (a >> 16) & 0xffff; //高2字节
unsigned short int c = a & 0xffff; //低2字节
#3
unsigned int a = 56505;
unsigned short int b = *((unsigned short*)&a); //高2字节
unsigned short int c = *(((unsigned short*)&a) + 1); //高2字节
#4
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]);//大端内存
#5
unsigned int a = 56505;
unsigned short int b = (a >> 16) & 0xffff; //高2字节
unsigned short int c = a & 0xffff; //低2字节
有一个32位整数如:65606
如何表示它的高2字节和低2字节
++
地址要分大小端
简单的移位运算,就不需要了分大小端。
平台自己会处理好这个问题的。
#6
union
{
int32_t int_member;
uint8_t char_member[4];
}
然后搞个宏判断大小端。
#1
要分大小端吧
#2
unsigned int a = 56505;
unsigned short int b = (a >> 16) & 0xffff; //高2字节
unsigned short int c = a & 0xffff; //低2字节
有一个32位整数如:65606
如何表示它的高2字节和低2字节
#3
unsigned int a = 56505;
unsigned short int b = (a >> 16) & 0xffff; //高2字节
unsigned short int c = a & 0xffff; //低2字节
有一个32位整数如:65606
如何表示它的高2字节和低2字节
unsigned int a = 56505;
unsigned short int b = *((unsigned short*)&a); //高2字节
unsigned short int c = *(((unsigned short*)&a) + 1); //高2字节
#4
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]);//大端内存
#5
unsigned int a = 56505;
unsigned short int b = (a >> 16) & 0xffff; //高2字节
unsigned short int c = a & 0xffff; //低2字节
有一个32位整数如:65606
如何表示它的高2字节和低2字节
++
地址要分大小端
简单的移位运算,就不需要了分大小端。
平台自己会处理好这个问题的。
#6
union
{
int32_t int_member;
uint8_t char_member[4];
}