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.
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.
Because the leading zero makes the whole number be treated as octal
And 2 + 3x8 + 2x8^2 + 1x8^3 = 666
The leading 0
in 01232
means that the rest of the number is interpreted as octal, representing
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.