Octal and hexadecimal integers
Integer values can be expressed in decimal notation (base 10), octal notation (base 8), and hexadecimal notation (base 16).
Decimal (base 10) integers (other than 0
) must not
start with a 0
.
Octal (base 8) integers have a prefix of 0
(zero),
followed by octal digits 0
to 7
.
Hexadecimal (base 16) integers have a prefix of 0x or 0X, followed by hexadecimal
digits 0
to 9
,
a
to f
, or
A
to F
.
Floats can't be expressed in octal or hexadecimal.
Examples:
# octal $value = 0777 # evaluates to decimal 511 $value = 0789 # Error, invalid octal $value = 0777.3 # Error, invalid octal # hexadecimal $value = 0x777 # evaluates to decimal 1911 $value = 0xdef # evaluates to decimal 3567 $value = 0Xdef # same as above $value = 0xDEF # same as above $value = 0xLMN # Error, invalid hex