integer
Module with some integer utility functions.
- class IntegerUtils
Bases:
object
Class container for integer utility functions.
- static GetBytesNumber(data_int: int) int
Get the number of bytes of the specified integer.
- Parameters:
data_int (int) – Data integer
- Returns:
Number of bytes
- Return type:
int
- static ToBytes(data_int: int, bytes_num: Optional[int] = None, endianness: typing_extensions.Literal[little, big] = 'big', signed: bool = False) bytes
Convert integer to bytes.
- Parameters:
data_int (int) – Data integer
bytes_num (int, optional) – Number of bytes, automatic if None
endianness ("big" or "little", optional) – Endianness (default: big)
signed (bool, optional) – True if signed, false otherwise (default: false)
- Returns:
Bytes representation
- Return type:
bytes
- static FromBinaryStr(data: Union[bytes, str]) int
Convert the specified binary string to integer.
- Parameters:
data (str or bytes) – Data
- Returns:
Integer representation
- Return type:
int
- static ToBinaryStr(data_int: int, zero_pad_bit_len: int = 0) str
Convert the specified integer to a binary string.
- Parameters:
data_int (int) – Data integer
zero_pad_bit_len (int, optional) – Zero pad length in bits, 0 if not specified
- Returns:
Binary string
- Return type:
str