为什么用前导零表示八进制数字? [英] Why are leading zeroes used to represent octal numbers?

查看:485
本文介绍了为什么用前导零表示八进制数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想知道为什么使用前导零()来表示八进制数字,而不是例如-0o.使用0o会很有帮助,但不会引起领先于0的问题(例如JavaScript中的parseInt('08');).这种设计选择背后的原因是什么?

I've always wondered why leading zeroes (0) are used to represent octal numbers, instead of — for example — 0o. The use of 0o would be just as helpful, but would not cause as many problems as leading 0es (e.g. parseInt('08'); in JavaScript). What are the reason(s) behind this design choice?

推荐答案

所有现代语言都从C导入此约定,然后从B导入,然后从BCPL导入.

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

除了BCPL将#1234用于八进制,将#x1234用于十六进制. B偏离了此约定,因为#是B中的一元运算符(整数到浮点转换),因此无法使用#1234,并且#作为基本指示符被替换为0.

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.

B的设计者试图使语法非常紧凑.我猜这是他们没有使用两个字符前缀的原因.

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.

这篇关于为什么用前导零表示八进制数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆