If numbers are prefixed with 0
, it's octal representation.
Similarly, if numbers are prefixed with 0x
or 0X
, it's hexadecimal reprepsentation.
0x10
# => 16
0x100
# => 256
BTW, You can convert numbers to octal, hexadecimal, binary representation using %
operator or sprintf
:
'%o' % 512
=> "1000"
'%x' % 256
# => "100"
'%x' % 512
# => "200"
'%b' % 3
# => "11"