-3

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.

Opera GX Browser Console

So I was curious and tried this.

enter image description here

Steve
  • 115
  • 8

2 Answers2

0

Because the leading zero makes the whole number be treated as octal

And 2 + 3x8 + 2x8^2 + 1x8^3 = 666

Vivick
  • 3,434
  • 2
  • 12
  • 25
0

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.

Zev Chonoles
  • 1,063
  • 9
  • 13
  • You mean analogous to the modern [`0o`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_octal#valid_octal_numbers)? – InSync Aug 09 '23 at 23:02