Wie erhalte ich die ersten 11 Bits eines 32-Bit-Integers mit 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))
Ergebnis:
0b01010000001000000000000000000001
0b00000000000000000000000000000001
Während ich es wollte
0b**01010000001**000000000000000000001
0b000000000000000000000**01010000001**