What is being done in this bit shifting operation?
(INBuffer[3] << 8) + INBuf开发者_Go百科fer[2]
Is this essentially moving the bit in INBuffer[3] into INBuffer[2] or [3] being zero'ed out then added to [2]?
This is a simple way to make a 16 bit value from two 8 bit values.
INBuffer[3] = 0b01001011;
INBuffer[2] = 0b00001001;
INBuffer[3]<<8 // 0b0100101100000000;
(INBuffer[3]<<8) + INBuffer[2] // 0b0100101100001001
Usually this is represented as
(INBuffer[3]<<8) | INBuffer[2];
Depending on the language this most likely computes
InBuffer[3] * 256 + InBuffer[2]
or (which is most likely the same depending on the language) performes packing two bytes into one 16-bit word.
精彩评论