为什么二进制数转换为十六进制数比十进制数更简单? (对于个人电脑)
有人告诉我:
“计算机将二进制数据转换为十六进制 (hex) 数字系统,因为 它比将数据转换为十进制数字要简单得多。”
为什么它不那么复杂?
I've been told this :
"Computers convert binary data into the hexadecimal (hex) number system because
it is much less complex than converting data into decimal numbers."
Why it is less complex?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我支持你在标题中混合二进制和十进制。为了将二进制转换为十六进制,您只需构建 for 组并对每个块进行替换:
为了将十进制转换为十六进制,您必须应用除法和 mod 计算:
I support you mixed up binary and decimal in the title. In order to convert a binary into hex you only have to build groups of for and do a substitution for each block:
In order to convert decimal to hex you'll have to apply divisions and mod calculations:
计算机不会将二进制“转换”为十六进制,就像不会将二进制“转换”为十进制一样。对于现代计算机来说,除了二进制以外的任何东西都只是“为了人类的舒适”。 (这并不完全正确,IEEE 754 base 10是一个反例。)
二进制和十六进制很容易转换,因为一个十六进制字符正好是 4 位(16 个值之一,0-15),两个十六进制字符是 8 位(一个八位字节)。这个很好的属性对于十进制来说并不正确,因为一位十进制数字是“3 位和一些变化”(10 个值之一,0-9)——没有漂亮的对齐方式。
(有关手工数学和示例,请参阅霍华德的答案)。
快乐编码。
Computers don't "convert" binary to hex any more than they convert binary to decimal. Anything but binary to a modern computer is just "for human comfort". (This isn't entirely true, IEEE 754 base 10 is a counter-example.)
Binary and hex are rather easily convertible because a hex character is exactly 4 bits (one of 16 values, 0-15) and two hex characters are 8 bits (one octet). This nice property is not true for decimal as one decimal digit is "3 bits and some change" (one of 10 values, 0-9) -- there is no pretty alignment.
(See Howards answer for the hand-math and examples).
Happy coding.