[plum.int.bitfields] Module Reference

Interpret bytes as an unsigned integer with bit fields.

class plum.int.bitfields.BitFields(value, **kwargs)

Interpret bytes as an unsigned integer with bit fields.

class plum.int.bitfields.BitFieldsType(name, bases, namespace, nbytes=None, byteorder=None, default=None, ignore=None)

BitFields type metaclass.

Create custom BitFields subclass. For example:

Parameters:
  • nbytes (int) – number of bytes
  • byteorder (str) – 'big' or 'little'
  • default (int) – default value (before applying bit field values)
  • ignore (int) – mask applied during comparison to ignore bit fields

For example:

>>> from plum.int.bitfields import BitFields, BitField
>>> class MyBits(BitFields, nbytes=1, byteorder='big', default=0, ignore=0x80):
...     nibble: int = BitField(pos=0, size=4)
...     threebits: int = BitField(pos=4, size=3)
...
>>>