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?
Numbers starting with 0 are interpreted as octal numbers.
010 => 8
020 => 16
0777 => 511
Octal numbers. Not just in Ruby - most programming languages think that when you start a number with a zero, it's in base 8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With