Matchbox 0.2

Integer Literals

An integer literal writes an integer value directly in source code. Matchbox 0.2 supports decimal, binary, octal, and hexadecimal notation.

Notation Prefix Example Decimal Value
Decimal None 42 42
Binary 0b 0b101010 42
Hexadecimal 0x 0x2A 42
Octal 0o 0o52 42

Integer literals can be used anywhere an integer expression is accepted:

var decimal = 42
var binary = 0b101010
var hexadecimal = 0x2A
var octal = 0o52

Digit Separators

Underscores can separate groups of digits to make large integer literals easier to read. They do not change the value:

var population = 1_234_567
print(1_234_567)

Both literals in this example represent the value 1234567.

Negative Values

Use a minus sign before an integer value:

var temperature = -10
var mask = -(0x20)

In 0.2, a minus sign can be written directly before a decimal literal. Put a non-decimal literal in parentheses when applying unary minus.

The valid literal range is the signed 32-bit int range described in Integer Representation. Values outside that range should not be used.