为什么我们不使用 base64 而是使用十六进制?
如果我们使用十六进制,因为它是二进制的简化,可以让程序员更轻松,比二进制更容易阅读,并且可以携带更多数据(等等),为什么我们不跳到下一个逻辑步骤,base64?
示例:
十进制:
1,000,00010
以二进制表示:
0b111101000010010000002
十六进制:
0xf4240<子>16
Clearly, the base64 representation of the above will be even more compact and succinct than even the hex representation.
就此而言,我们为什么不使用任意大的 2n 基本系统呢?为什么要特别停在十六进制?
If we use hex because it's a simplification of binary that makes things easier on the programmer, is easier to read than binary, and carries more data, (etc.,) why do we not jump to the next logical step, base64?
Example:
In decimal:
1,000,00010
In binary:
0b111101000010010000002
In hex:
0xf424016
Clearly, the base64 representation of the above will be even more compact and succinct than even the hex representation.
For that matter, why don't we use an arbitrarily large 2n base system? Why stop at hex, specifically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
十六进制有一个有用的属性,即使用两个数字表示一个字节。这对于查看原始内存、内存地址等非常方便。在我的 PDP 时代,我们经常使用八进制,因为我们可以更轻松地读取机器代码。 Base-64 不提供如此好的整除性:它是 6 位,因此 3 个字节是 4 位数字。
Hex has a useful property of using two digits to a single byte. This is very convenient for looking at raw memory, memory addresses, etc. Back in my PDP days we used octal a lot, because we could read machine code easier. Base-64 does not offer such nice divisibility: it's 6 bits, so it is 4 digits for 3 bytes.
快问一下,符号
K
的二进制或十进制值是多少? (或者,如果我告诉你将K
个对象从一堆中分离出来,你能做到这一点而不必花几分钟弄清楚该值的实际含义吗?)如果你必须在背诵时进行计数字母歌曲,您就会意识到使用 base-64 作为书面数字系统的问题是什么。哎呀,你必须用一首歌来记住26个符号的顺序是什么(至少我是这样),你怎么能记住其中的64个呢?
Quick, what's the binary or decimal value of the symbol
K
? (Or if I tell you to separateK
objects out from a pile, can you do it without having to spend a few minutes figuring out what that value actually means?)If you have to count while reciting the alphabet song, you will realize what the problem with using base-64 is as a written number system. Heck, you have to use a song to remember what the order of 26 symbols is (at least I do), how can you remember 64 of them?
Base64 已被用作多种任务的编码系统。例如,在 Java 中,有许多实现像这里< /a> 例如。它对于传输 xml 中的编码数据很有用。
Base64 is already used as an encoding system for a variety of tasks. In Java for example there are many implementations like here for example. It can be useful for transporting encoded data in xml.