可能简单的按位移位问题 [英] Probably simple bitwise shifting question
本文介绍了可能简单的按位移位问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
unsigned short int temp, temp2;
temp = 0xbc61; // 1011110001100001
// temp2 has to be 0x61 (01100001) but I don't know how to shift, mask or whatever
temp2 = (temp << 8); // this doesnt work, because I get 0x6100 (110000100000000)
推荐答案
要选择1011110001100001
的最低8位,您需要对11111111
执行按位与运算:
To select the 8 lowest bits of 1011110001100001
, you need to perform a bitwise AND operation with 11111111
:
1011110001100001
& 0000000011111111
------------------
0000000001100001
也就是说,
temp2 = temp & 0xff; // or 255
这篇关于可能简单的按位移位问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文