Converts the given integer to a bytes object of given length and byte order. The default values are 32B width (which is the hash result width) and 'big', respectively.
(
value: int,
length: Optional[int] = None,
byte_order: Optional[Endianness] = None,
signed: Optional[bool] = None,
)
| 24 | TComparable = TypeVar("TComparable", bound="Comparable") |
| 25 | |
| 26 | def to_bytes( |
| 27 | value: int, |
| 28 | length: Optional[int] = None, |
| 29 | byte_order: Optional[Endianness] = None, |
| 30 | signed: Optional[bool] = None, |
| 31 | ) -> bytes: |
| 32 | """ |
| 33 | Converts the given integer to a bytes object of given length and byte order. |
| 34 | The default values are 32B width (which is the hash result width) and 'big', respectively. |
| 35 | """ |
| 36 | if length is None: |
| 37 | length = HASH_BYTES |
| 38 | |
| 39 | if byte_order is None: |
| 40 | byte_order = "big" |
| 41 | |
| 42 | if signed is None: |
| 43 | signed = False |
| 44 | |
| 45 | return int.to_bytes(value, length=length, byteorder=byte_order, signed=signed) |
| 46 | |
| 47 | |
| 48 | def from_bytes( |
no test coverage detected
searching dependent graphs…