当前位置: 技术问答>linux和unix
ARM写程序~~关于二进制数高低位赋值问题
来源: 互联网 发布时间:2016-07-09
本文导语: 如果有一个两个变量data1和data2,有一个16位的二进制数,要将高八位赋给data1,低八位赋给data2,怎么实现? | U16 val = 0x1234; U8 data1, data2; data1 = val>>8; //mov low 8 bits in val to data1 data2 = (U8)...
如果有一个两个变量data1和data2,有一个16位的二进制数,要将高八位赋给data1,低八位赋给data2,怎么实现?
|
U16 val = 0x1234;
U8 data1, data2;
data1 = val>>8; //mov low 8 bits in val to data1
data2 = (U8)val; //mov high 8 bits in val to data2
|
有问题啊,data1= val>>8;//为0x12, 明明是高位,另外大数端,小数端不分?
|
int i = 0x1234,low,high;
low = i & 0xff;
high = i >> 8;
low = i & 0xff;
high = i >> 8;