What does least significant byte mean?

后端 未结 4 1071
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 19:43

I have to implement a method that writes a byte to an ostream object. Let\'s just called this ostream object strobj. I also have a bit

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 20:14

    Your int consist of several bytes (most likely 2, 4 or 8 bytes). Similar to the concept of the least significant bit, the least significant byte is the byte that has the less weight in the value of the entire integer. Depending on the endianness of your system, it may be the first or last byte in terms of memory.

    To extract the least significant byte, bitwise-AND the number with one byte worth of 1s, i. e. 255:

    int LSB = (someInteger & 0xFF);
    

提交回复
热议问题