PyDocs

Nav

Python Runtime Services

int.from_bytes

builtins

classmethod of int · Added in 3.2
  • int.from_bytes(bytes, byteorder='big', *, signed=False)
Return the integer represented by the given array of bytes.

bytes
  Holds the array of bytes to convert.  The argument must either
  support the buffer protocol or be an iterable object producing
  bytes.  Bytes and bytearray are examples of built-in objects that
  support the buffer protocol.
byteorder
  The byte order used to represent the integer.  If byteorder is
  'big', the most significant byte is at the beginning of the byte
  array.  If byteorder is 'little', the most significant byte is at
  the end of the byte array.  To request the native byte order of
  the host system, use sys.byteorder as the byte order value.
  Default is to use 'big'.
signed
  Indicates whether two's complement is used to represent the
  integer.
Changed in 3.11
  • 3.11: Added default argument value for byteorder.
1 Example
>>> int.from_bytes(b'\x00\x10', byteorder='big')
16
>>> int.from_bytes(b'\x00\x10', byteorder='little')
4096
>>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=True)
-1024
>>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=False)
64512
>>> int.from_bytes([255, 0, 0], byteorder='big')
16711680
from the Python docs
See Also
No see-alsos for builtins/int.from_bytes
0 Notes
No notes for int.from_bytes