Probably simple bitwise shifting question

前提是你 提交于 2019-12-14 03:03:27

问题


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)


回答1:


To select the 8 lowest bits of 1011110001100001, you need to perform a bitwise AND operation with 11111111:

  1011110001100001
& 0000000011111111
------------------
  0000000001100001

That is,

temp2 = temp & 0xff;  // or 255


来源:https://stackoverflow.com/questions/56610742/probably-simple-bitwise-shifting-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!