为什么了解如何在数字基数之间进行转换很有用?
我们正在学习如何将二进制转换为十进制(反之亦然)以及其他基数转换方法,但我不明白这些知识的必要性。
在不同基数之间转换数字有实际用途吗?
We are learning about converting Binary to Decimal (and vice-versa) as well as other base-conversion methods, but I don't understand the necessity of this knowledge.
Are there any real-world uses for converting numbers between different bases?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
处理 Unicode 转义码时 — Javascript 中的
'\u2014'
是 HTML 中的—
调试时 — 许多调试器以十六进制显示所有数字
在编写位掩码时,以十六进制指定 2 的幂(或通过编写
1 << 4
)会更方便When dealing with Unicode escape codes—
'\u2014'
in Javascript is—
in HTMLWhen debugging— many debuggers show all numbers in hex
When writing bitmasks— it's more convenient to specify powers of two in hex (or by writing
1 << 4
)在 这篇文章我描述了一个具体的用例。简而言之,假设您想要使用某种传输机制传输一系列字节,但您不能简单地将有效负载作为字节传递,因为您无法发送二进制内容。假设您只能使用 64 个字符来对有效负载进行编码。解决此问题的方法是将字节(8 位字符)转换为 6 位字符。这里就需要用到数字转换了。将这一系列字节视为一个以 256 为基数的大数字。然后将其转换为以 64 为基数的数字,就完成了。新的 64 基数的每个数字现在表示编码有效负载的一个字符...
In this article I describe a concrete use case. In short, suppose you have a series of bytes you want to transfer using some transport mechanism, but you cannot simply pass the payload as bytes, because you are not able to send binary content. Let's say you can only use 64 characters for encoding the payload. A solution to this problem is to convert the bytes (8-bit characters) into 6-bit characters. Here the number conversion comes into play. Consider the series of bytes as a big number whose base is 256. Then convert it into a number with base 64 and you are done. Each digit of the new base 64 number now denotes a character of your encoded payload...
如果您有一个设备(例如硬盘驱动器),它只能具有一定数量的状态,则您只能在具有那么多状态的数字系统中进行计数。
因为计算机的字节只有on和off,所以只能表示0和1。因此使用了base2系统。
如果您的设备有 3 个状态,则可以表示 0、1 和 2,因此计入基数为 3 的系统。
If you have a device, such as a hard drive, that can only have a set number of states, you can only count in a number system with that many states.
Because a computer's byte only have on and off, you can only represent 0 and 1. Therefore a base2 system is used.
If you have a device that had 3 states, you could represent 0, 1 and 2, and therefore count in a base 3 system.