-
Notifications
You must be signed in to change notification settings - Fork 0
Description
I was initially confused by the bit fields being defined in little endian order (granted, I should've read the documentation closer...). This is particularly confusing when assigning an int to the base attribute, as the bits are then printed in what feels like the opposite order since it is printed from LSB to MSB.
For example, assigning 0x80 to the base attribute indeed sets the MSB to one, but the bits are printed LSB to MSB:
GenStatus = bitfield.make_bf(name='GenStatus', basetype=c_uint8,
fields=[
('DWNM', c_bool, 1),
('UPM', c_bool, 1),
('CCWM', c_bool, 1),
('CWM', c_bool, 1),
('OSLR', c_bool, 1),
('DES', c_bool, 1),
('EXEC', c_bool, 1),
('HRES', c_bool, 1),
])>>> g = GenStatus()
>>> g.base = 0x80
>>> g
GenStatus(DWNM=0, UPM=0, CCWM=0, CWM=0, OSLR=0, DES=0, EXEC=0, HRES=1)Would you be interested in changing the default __repr__ method to print the fields in big endian order? I find that is more intuitive to read, especially for bit fields.
Or perhaps we could add an optional argument to the make_bf function to use a BigEndian struct? That might have wider-reaching implications across the module, though.
This isn't a big deal, as the library works well for what I need to do, and I won't be printing the bit fields to the console in production; I was just curious to hear your thoughts.
Thanks for creating this library!