1

I can't figure it out why, when I type 67 in Rails' console, the output is 67, but 067 returns 55.

Can someone explain this to me?

0

1 Answer 1

1

Starting a number with a 0 denotes that the number is in octal notation.

When you type in 067, you're really saying "67 in octal notation" or "678 (67 base 8)". When Ruby outputs that number it converts it to decimal (base 10).

Since 678 == 5510, Ruby outputs 55.

Check out "How do I convert an octal number to decimal in Ruby?" that mentions the leading 0.

See "Octal to decimal converter" for an octal calculator:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.