Skip to content

Integers

Constants

Action Code Details
Min int
-sys.maxsize
Max int
sys.maxsize

Create

int() throws ValueError if the input cannot be parsed

Action Code Details
Define integer
x = 10
Cannot contain decimal values or result will be float.
Define integer from scientific notation
x = int(1e6)
Cast is needed otherwise result is float
Binary integer
[sign]0b[b2int]
-0b10 (-2)
Hex integer
[sign]0x[b16int]
e.g., -0xF (-16)
Integer from string
int(x)
Integer from hex string (base 16)
int(x, 16)
e.g., DEADBEEF
Integer from string with base determined by prefix
int(x, 0)
Base 10 by default, base-16 for 0x, base-2 for 0b
Integer from string according to locale
locale.atoi(x)
Unsigned integer from bytes
int.from_bytes(x, byteorder='big')
Signed integer from bytes
int.from_bytes(x, byteorder='big', signed=True)

Test

Action Code Details
Is integer
type(x) is int

Extract

Action Code Details
Hash
hash(x)

Convert

Action Code Details
To string
str(x)
To string, with comma as thousands separator
f'{x:,}'
To hex string
hex(x)
Format: `[sign] ['0x'] integer
To bytes
x.to_bytes(8, byteorder='big')
OverflowError is raised if the integer is not representable with the given number of bytes
To bytes
x.to_bytes(8, byteorder='big', signed=True)
Count to byte array (mutable)
bytearray(x)