An integer is a number without a fractional component.

Length Signed Unsigned
8-bit i8 u8
16-bit i16 u16
32-bit i32 u32
64-bit i64 u64
128-bit i128 u128
arch isize usize

signed integers can hold positive and negative values. unsigned can hold positive values only.

Signed numbers are stored using two’s complement representation, which means that it uses the binary digit with the greatest value as the sign to indicate whether the binary number is positive or negative; when the most significant bit is 1 the number is signed as negative and when the most significant bit is 0 the number is signed as positive.

Each signed variant can store numbers from $-(2^{n - 1})$ to $2^{n-1} - 1$ inclusive, where n is the number of bits that variant uses. and, Unsigned variants can store numbers from $0$ to $2^n - 1$.

“arch”: 64 bits if you’re on a 64-bit architecture and 32 bits if you’re on a 32-bit architecture.

Number literals can also use _ as a visual separator to make the number easier to read, such as 1_000, which will have the same value as if you had specified 1000. (that’s cool)

integer division also truncates the floating part of the result.

Number literals Example
Decimal 98_222
Hex 0xff
Octal 0o77
Binary 0b1111_0000
Byte (u8 only) b'A'