为什么以0x pfixed十六进制数$ P $? [英] Why are hexadecimal numbers prefixed with 0x?
问题描述
为什么十六进制数prefixed为 0X
?
据我所知,preFIX的用法,但我不明白为什么被选为 0X
的意义。
Why are hexadecimal numbers prefixed as 0x
?
I understand the usage of the prefix but I don't understand the significance of why 0x
was chosen.
推荐答案
简单地说:的 0
告诉它在处理一个恒定的解析器(而不是一个标识符/保留字)。仍然需要一些东西来指定基数:在 X
是一个任意的选择
Short story: The 0
tells the parser it's dealing with a constant (and not an identifier/reserved word). Something is still needed to specify the number base: the x
is an arbitrary choice.
龙的故事:在60年代,prevalent编程数字系统是十进制和的八的 - 大型机有每字节12,24或36位,这是3 =很好LOG2整除(8)。
Long story: In the 60's, the prevalent programming number systems were decimal and octal — mainframes had 12, 24 or 36 bits per byte, which is nicely divisible by 3 = log2(8).
在BCPL语言中使用的语法 8 1234
为八进制数字。当肯·汤普逊从BCPL创建B,他使用了 0
preFIX代替。这是伟大的,因为
The BCPL language used the syntax 8 1234
for octal numbers. When Ken Thompson created B from BCPL, he used the 0
prefix instead. This is great because
- 整型常量现在总是由一个单一的令牌,
- 解析器仍然可以告诉马上它有一个恒定的,
- 解析器可以立即告诉底座(
0
是在这两个基地是相同的), - 这是数学理智(
00005 == 05
)和 - 没有precious(在
#123
的)。 需要特殊字符
- an integer constant now always consists of a single token,
- the parser can still tell right away it's got a constant,
- the parser can immediately tell the base (
0
is the same in both bases), - it's mathematically sane (
00005 == 05
), and - no precious special characters are needed (as in
#123
).
当下选自B创建,需要十六进制数出现(在PDP-11有16位字)及以上的所有的点仍然有效。由于八进制仍然需要其他机器, 0X
中任意选择( 00
可能是排除了别扭)。
When C was created from B, the need for hexadecimal numbers arose (the PDP-11 had 16-bit words) and all of the points above were still valid. Since octals were still needed for other machines, 0x
was arbitrarily chosen (00
was probably ruled out as awkward).
C#是C的后代,所以它继承了语法。
C# is a descendant of C, so it inherits the syntax.
这篇关于为什么以0x pfixed十六进制数$ P $?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!