lewis.utils.byte_conversions
Members
Converts an floating point number to an unsigned set of bytes. |
|
Converts an integer to an unsigned set of bytes with the specified length (represented as a string). |
|
Convert a set of bytes to a floating point number |
|
Converts an unsigned set of bytes to an integer. |
- lewis.utils.byte_conversions.float_to_raw_bytes(real_number: float, low_byte_first: bool = True) bytes [source]
Converts an floating point number to an unsigned set of bytes.
- Parameters:
real_number – The float to convert.
low_byte_first – Whether to put the least significant byte first. True by default.
- Returns:
A string representation of the bytes.
- lewis.utils.byte_conversions.int_to_raw_bytes(integer: int, length: int, low_byte_first: bool) bytes [source]
Converts an integer to an unsigned set of bytes with the specified length (represented as a string). Unless the integer is negative in which case it converts to a signed integer.
If low byte first is True, the least significant byte comes first, otherwise the most significant byte comes first.
- Parameters:
integer – The integer to convert.
length – The length of the result.
low_byte_first – Whether to put the least significant byte first.
- Returns:
string representation of the bytes.
- lewis.utils.byte_conversions.raw_bytes_to_float(raw_bytes: bytes) float [source]
Convert a set of bytes to a floating point number
- Parameters:
raw_bytes – A string representation of the raw bytes.
- Returns:
float: The floating point number represented by the given bytes.
- lewis.utils.byte_conversions.raw_bytes_to_int(raw_bytes: bytes, low_bytes_first: bool = True) int [source]
Converts an unsigned set of bytes to an integer.
- Parameters:
raw_bytes – A string representation of the raw bytes.
low_bytes_first – Whether the given raw bytes are in little endian or not. True by default.
- Returns:
The integer represented by the raw bytes passed in.