Skip to content

Integers

There are five signed integer types, and five unsigned integer types:

Type Length Minimum Value Maximum Value
Int8 8 -128 127
Int16 16 −32,768 32,767
Int32 32 −2,147,483,648 2,147,483,647
Int64 64 −263 263 - 1
Int128 128 −2127 2127 - 1
UInt8 8 0 255
UInt16 16 0 65,535
UInt32 32 0 4,294,967,295
UInt64 64 0 264 - 1
UInt128 128 0 2128 - 1

An integer literal is an optional + or - sign, followed by a sequence of digits and underscores, optionally followed by a suffix. If no suffix is present, the literal's type is Int32 if the value fits into Int32's range, and Int64 otherwise. Integers outside Int64's range must always be suffixed:

1 # Int32

1_i8   # Int8
1_i16  # Int16
1_i32  # Int32
1_i64  # Int64
1_i128 # Int128

1_u8   # UInt8
1_u16  # UInt16
1_u32  # UInt32
1_u64  # UInt64
1_u128 # UInt128

+10 # Int32
-20 # Int32

2147483647  # Int32
2147483648  # Int64
-2147483648 # Int32
-2147483649 # Int64

9223372036854775807     # Int64
9223372036854775808_u64 # UInt64

Suffix-less integer literals larger than Int64's maximum value but representable within UInt64's range are deprecated, e.g. 9223372036854775808.

The underscore _ before the suffix is optional.

Underscores can be used to make some numbers more readable:

1_000_000 # better than 1000000

Binary numbers start with 0b:

0b1101 # == 13

Octal numbers start with a 0o:

0o123 # == 83

Hexadecimal numbers start with 0x:

0xFE012D # == 16646445
0xfe012d # == 16646445