Why are leading zeroes used to represent octal numbers?

人盡茶涼 提交于 2019-11-27 16:02:07

All modern languages import this convention from C, which imported it from B, which imported it from BCPL.

Except BCPL used #1234 for octal and #x1234 for hexadecimal. B has departed from this convention because # was an unary operator in B (integer to floating point conversion), so #1234 could not be used, and # as a base indicator was replaced with 0.

The designers of B tried to make the syntax very compact. I guess this is the reason they did not use a two-character prefix.

"0b" is often used for binary rather than for octal. The leading "0" is, I suspect for "O -ctal".

If you know you are going to be parsing octal then use parseInt('08', 10); to make it treat the number as base ten.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!