I was wondering if I could quickly remove the 0 from 01232 by dividing it by 1 in my browsers console but all of a sudden it gives me 666.
So I was curious and tried this.
2
Because the leading zero makes the whole number be treated as octal
And 2 + 3×8 + 2×8^2 + 1×8^3 = 666
The leading 0 in 01232 means that the rest of the number is interpreted as octal, representing
0
01232
1 x 8^3 + 2 x 8^2 + 3 x 8^1 + 2 x 8^0 = 512 + 128 + 24 + 2 = 666
This prefix (analogous to 0x for hexadecimal) dates back to the early days of Unix; see here.
0x
Click here to cancel reply.
2
Answers
Because the leading zero makes the whole number be treated as octal
And 2 + 3×8 + 2×8^2 + 1×8^3 = 666
The leading
0
in01232
means that the rest of the number is interpreted as octal, representingThis prefix (analogous to
0x
for hexadecimal) dates back to the early days of Unix; see here.