C#, bits & bytes - How do I retrieve bit values from a byte?

前端 未结 5 1039
陌清茗
陌清茗 2020-12-29 08:04

I\'m reading some values from a single byte. I\'m told in the user-manual that this one byte contains 3 different values. There\'s a table that looks like this:

5条回答
  •  醉话见心
    2020-12-29 08:24

    You can do this via bitwise arithmetic:

    uint precision = (thatByte & 0xe0) >> 5,
        scale = (thatByte & 0x18) >> 3,
        size = thatByte & 7;
    

提交回复
热议问题