Integers

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

TypeLengthMinimum ValueMaximum Value
Int88-128127
Int1616−32,76832,767
Int3232−2,147,483,6482,147,483,647
Int6464−263263 - 1
Int128128−21272127 - 1
UInt880255
UInt1616065,535
UInt323204,294,967,295
UInt64640264 - 1
UInt12812802128 - 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. 1 # Int32
  2. 1_i8 # Int8
  3. 1_i16 # Int16
  4. 1_i32 # Int32
  5. 1_i64 # Int64
  6. 1_i128 # Int128
  7. 1_u8 # UInt8
  8. 1_u16 # UInt16
  9. 1_u32 # UInt32
  10. 1_u64 # UInt64
  11. 1_u128 # UInt128
  12. +10 # Int32
  13. -20 # Int32
  14. 2147483647 # Int32
  15. 2147483648 # Int64
  16. -2147483648 # Int32
  17. -2147483649 # Int64
  18. 9223372036854775807 # Int64
  19. 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. 1_000_000 # better than 1000000

Binary numbers start with 0b:

  1. 0b1101 # == 13

Octal numbers start with a 0o:

  1. 0o123 # == 83

Hexadecimal numbers start with 0x:

  1. 0xFE012D # == 16646445
  2. 0xfe012d # == 16646445