如何获得 32 位 int 的前 11 位ctypes
?
import ctypes
class Fields(ctypes.Structure):
_pack_ = 1
_fields_ = [('a', ctypes.c_uint, 11)]
class BitField(ctypes.Union):
_pack_ = 1
_fields_ = [('b', Fields),
('raw', ctypes.c_uint)]
bf = BitField()
bf.raw = 0b01010000001000000000000000000001
print('0b{:0>32b}'.format(bf.raw))
print('0b{:0>32b}'.format(bf.b.a))
结果:
0b01010000001000000000000000000001
0b00000000000000000000000000000001
而我想要
0b 01010000001 000000000000000000001 0b000000000000000000000 01010000001