【发布时间】:2016-04-14 09:12:55
【问题描述】:
我有一个 16 位寄存器
- 位 0 的值为 0
- 位 1...2 的值为 3
- 位 3 的值为 1
- 位 4 的值为 1
所以最后我的寄存器中写入的值是 30,因为:
(0 x 1) + (3 x 2) + (1 x 8) + (1 x 16) = 30
现在我想做反向操作以获取位中写入的值:
(30 & 1) / 1 = 0
(30 & 2) / 2 = 1 (this is wrong, it should be 3)
(30 & 8) / 8 = 1
(30 & 16) / 16 = 1
我做错了什么?
【问题讨论】:
标签: bit-manipulation bit bit-shift cpu-registers bit-fields