jchi2241 jchi2241 - 1 year ago 39
Ruby Question

Please explain how Ruby interprets numbers

When the following numbers are entered into irb, I get the following results:

50 #=> 50
050 #=> 40
030 #=> 24
005 #=> 5


Why does
050
equal
40
rather than
50
,
030 == 30
,
005 == 5
? What's happening?

Answer Source

Numbers starting with 0 are interpreted as octal numbers.

010 => 8
020 => 16
0777 => 511
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download