Integer Types
Integer types are divided into two categories: signed (e.g., Int8, Int64) and unsigned (e.g., UInt8, UInt64), where the numeric suffix indicates the bit width. Int64 is the default integer type—when an integer literal has no type context, the compiler infers it as Int64.
Integer literals support four numeral systems: decimal (no prefix), binary (0b or 0B), octal (0o or 0O), and hexadecimal (0x or 0X). You can use underscores _ as separators to improve readability, such as 1_000_000.
You can explicitly specify the type of a literal using suffixes: i8 for Int8, u64 for UInt64, and so on. The code on the right demonstrates integer literals in different numeral systems and types.
Note
Using
Int64 is preferred because its range is large enough (-2^63 to 2^63-1), avoiding unnecessary type conversions.Try adding an octal literal and printing the result.