Integer Methods

int.from_bytes()

Interpret a bytes-like object or iterable of integer byte values as a single integer. Byte order controls significance, not bit order inside each byte. With signed=True, the most significant bit is a sign bit in two’s complement. Empty input represents zero. Invalid byte values or order raise ValueError; incompatible input raises TypeError. Use int(text, base) for textual digits instead.

Formal Syntax & Structure

python syntaxpython
int.from_bytes(bytes, byteorder='big', *, signed=False)

Parameters & Attributes

NameTypeDescription
bytesbytes-like | Iterable[int]Binary data or iterable of integers from 0 to 255.
byteorderstrbig puts the most significant byte first; little puts it last.
signedboolUse signed two’s-complement interpretation when true; keyword-only.

Return Value

int

Integer represented by the supplied bytes.

Working Example

Example Snippetpython
data = bytes.fromhex("01 02")print(int.from_bytes(data, "big"))print(int.from_bytes(data, "little"))print(int.from_bytes(b"\xff", signed=True))
Python Reference