16 lines
457 B
Python
16 lines
457 B
Python
from typing import Literal, Union
|
|
|
|
def int_from_hex(number: Union[str, int]) -> int:
|
|
return number if isinstance(number, int) else int(number, 16)
|
|
|
|
|
|
def int_from_bytes(
|
|
value: bytes,
|
|
byte_order: Literal["big", "little"] = "big",
|
|
signed: bool = False,
|
|
) -> int:
|
|
"""
|
|
Converts the given bytes object (parsed according to the given byte order) to an integer.
|
|
"""
|
|
return int.from_bytes(value, byteorder=byte_order, signed=signed)
|