API: BinField class.

class binfield.BinField(x=0, base=10, _parent=None)[source]

BinField representation.

Parameters:
  • x (typing.Union[int, str, bytes]) – Start value
  • base (int) – base for start value
  • _parent (typing.Optional[typing.Tuple[BinField, int]]) – Parent link. For internal usage only.

Note

Subclasses have getters for mapping indexes.

Note

Subclasses instances have getters and setters for mapping records.

_bit_size_

int - Number of bits necessary to represent in binary.

_value_

int - Internal value.

__int__()[source]

Convert to integer.

Return type:int
__index__()[source]

Special method used for bin()/hex/oct/slicing support.

Return type:int
__abs__()[source]

int mimic.

Return type:int
__gt__(other)[source]

Comparing logic.

Return type:bool
__ge__(other)[source]

Comparing logic.

Return type:bool
__lt__(other)[source]

Comparing logic.

Return type:bool
__le__(other)[source]

Comparing logic.

Return type:bool
__eq__(other)[source]

Comparing logic.

Return type:bool
__ne__(other)[source]

Comparing logic.

Return type:bool
__iand__(other)[source]

int mimic.

__ior__(other)[source]

int mimic.

__ixor__(other)[source]

int mimic.

__and__(other)[source]

int mimic.

Return type:BinField
__rand__(other)[source]

int mimic

Allows to call other & self

__or__(other)[source]

int mimic.

Return type:BinField
__ror__(other)[source]

int mimic

Allows to call other | self

__xor__(other)[source]

int mimic.

Return type:BinField
__rxor__(other)[source]

int mimic

Allows to call other ^ self

__iadd__(other)[source]

int mimic.

Raises:
  • OverflowError – Result not fills in data length
  • ValueError – negative result
__isub__(other)[source]

int mimic.

__add__(other)[source]

int mimic.

Return type:typing.Union[int, BinField]
Raises:ValueError – negative result
__radd__(other)[source]

int mimic

Allows to call other + self

__sub__(other)[source]

int mimic.

Return type:typing.Union[int, BinField]
__rsub__(other)[source]

int mimic

Allows to call other - self

__mul__(other)[source]

int mimic.

Return type:int
__rmul__(other)[source]

int mimic

Allows to call other * self

__lshift__(other)[source]

int mimic.

Return type:int
__rlshift__(other)[source]

int mimic

Allows to call other << self

__rshift__(other)[source]

int mimic.

Return type:int
__rrshift__(other)[source]

int mimic

Allows to call other >> self

__bool__(other)[source]

int mimic.

Return type:bool
__hash__()[source]

Hash.

__copy__()[source]

Copy logic.

Return type:BinField

Note

Uplink is destroyed on copy.

__getstate__()[source]

Pickling.

Return type:typing.Dict[str: int]
Raises:ValueError – Pickle of linked instance
__getnewargs__()[source]

required for pickle.

Return type:typing.Tuple
__setstate__(state)[source]

Restore from pickle.

__getitem__(item)[source]

Extract bits.

Return type:BinField
Raises:IndexError – Mapping is not available
__setitem__(key, value)[source]

Indexed setter

Raises:
  • TypeError – value type is not int
  • IndexError – key not found (or key is not string, no mapping)