What does least significant byte mean?

后端 未结 4 1081
佛祖请我去吃肉
佛祖请我去吃肉 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:31

    • When you look at a decimal number, say 507, the least significant digit would be the 7. Changing it to a 6 or an 8 would change the overall number a lot less than changing the 5.

    • When you look at a date, say May 14, 2013, the least significant part is the day (14) in terms of chronological ordering.

    • When you look at an unsigned 32-bit int (4 bytes), where the value of the integer is (256^3)*b3 + (256^2)*b2 + 256*b1 + b0 for the 4 bytes b0, b1, b2, b3, the least significant byte is the byte b0.

    You can get the least-significant byte from your int sumInt by doing char c = sumInt & 0xFF; as others have suggested.

提交回复
热议问题