什么情况下使用八进制?

发布于 2024-08-28 03:30:36 字数 120 浏览 8 评论 0原文

我经常看到二进制和十六进制使用,但从未见过八进制。然而,八进制在某些语言中使用时有其自己的约定(即,前导 0 表示八进制基数)。什么时候使用八进制?当人们使用八进制或八进制更容易推理时,有哪些典型情况?或者这只是一个品味问题?

I've seen binary and hex used quite often but never octal. Yet octal has it's own convention for being used in some languages (ie, a leading 0 indicating octal base). When is octal used? What are some typical situations when one would use octal or octal would be easier to reason about? Or is it merely a matter of taste?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

凉墨 2024-09-04 03:30:36

当一个字中的位数是 3 的倍数时,或者如果位的分组有意义以 3 为一组表示时,则使用八进制。示例是

  • 具有 18 位字大小的古代系统(主要是历史)
  • 具有 9 位字节的系统(主要是历史版本)
  • 9位的unix文件权限(3*3位,“rwxr-x---”0750)
  • 12位的unix文件权限(与9位版本相同,但在setuid、setgid和sticky前面添加了三位,01777但这里的字母更复杂)

在我大约 25 年的 IT 生涯中,除了 UNIX 文件权限位之外,我还没有遇到过任何八进制的使用。

但是,如果您的字中的位数是 4 的倍数,请务必使用十六进制。

Octal is used when the number of bits in one word is a multiple of 3, or if the grouping of the bits makes sense to notate in groups of 3. Examples are

  • ancient systems with 18bit word sizes (mostly historical)
  • systems with 9bit bytes (mostly historical)
  • unix file permissions with 9bits (3*3bits, "rwxr-x---" 0750)
  • unix file permissions with 12bits (the same as the 9bit version but adding three bits in front for setuid, setgid, and sticky, 01777 but the letters are more complicated here)

I have not encountered any uses of octal other than unix file permission bits during my about 25 years in IT.

If the number of bits in your word is a multiple of 4, however, please do use hex, by all means.

月寒剑心 2024-09-04 03:30:36

八进制用作表示 UNIX 系统上文件权限的简写。例如,文件模式 rwxr-xr-x 将为 0755

Octal is used as a shorthand for representing file permissions on UNIX systems. For example, file mode rwxr-xr-x would be 0755.

欢你一世 2024-09-04 03:30:36

当语法是旧时代的遗留物时使用八进制,在某些平台上它可能有意义(系统字并不总是 8 位的倍数)。现在使用的是十六进制。

Octal is used when the syntax is a relic from the ages when it perhaps made sense on some platform (system words haven't always been a multiple of 8 bits). Nowadays hex is the thing to use.

眼眸印温柔 2024-09-04 03:30:36

八进制被更频繁使用的主要原因之一是,在你的头脑中在八进制和二进制之间转换比十六进制到二进制更容易:你只需要记住 8 个八进制数字(0-7)的二进制表示。

回到过去,调试意味着从一排 LED 读取寄存器内容,或者使用一组切换开关输入数据,这是一个大问题。许多早期计算机的面板将 LED 和开关分成三个一组,以方便实现这一点。

然而,十六进制开始胜出,因为字大小是 8 位字节的倍数开始胜出,并且读取和输入二进制数据的需要变得不必要(使用控制台文本 UI 和后来的 GUI 调试器)。

One of the main reasons octal used to be more frequently used was that it is easier to convert between octal and binary in your head than hex to binary: you only have to remember the binary representation of the 8 octal digits (0-7).

Back in the days when debugging meant reading register contents from a row of LEDs, or entering data with an array of toggle switches, this was a big concern. The panels on many of these early computers grouped the LEDs and switches in groups of threes to facilitate this.

However, hex began to win out as word sizes that are multiples of 8-bit bytes began to win out, and the need to read and enter data in binary became unecessary (with console text UI and later GUI debuggers).

初相遇 2024-09-04 03:30:36

没想到还有数字显示!

其他几个用途来自:
http://en.wikipedia.org/wiki/Octal

Didn't think of this but Digital displays!

Several other uses from:
http://en.wikipedia.org/wiki/Octal

埋葬我深情 2024-09-04 03:30:36

如果鸟会数数,我猜它们会使用八进制。虽然大多数鸟类的羽毛“手”上有 3 个手指,但大多数是 Tetradactyly,意思是 4每只脚的脚趾。

If birds could count, my guess would be that they use octal. While most birds have 3 digits on their feathered "hands", most are Tetradactyly, meaning 4 toes on each foot.

沒落の蓅哖 2024-09-04 03:30:36

在航空电子设备中,ARINC 429 字标签几乎总是以八进制表示。

In avionics, ARINC 429 word labels are almost always expressed in octal.

懵少女 2024-09-04 03:30:36

音乐,只要你远离(大多数)升号和降号。

Music, as long as you stay away from (most) sharps and flats.

落日海湾 2024-09-04 03:30:36

仅供参考,有几个地方 Windows 和 javascript 自动确定以零为前缀的数字是八进制并转换该数字。

在 Windows 中,如果您 p​​ing 和地址如 10.0.2.010,它实际上会 ping 10.0.2.8

如果您输入它作为计算机的 ip/dns 地址,Windows 也会执行此操作

虽然它已被弃用,但 Javascript 在某些函数(如 parseInt)上默认执行此操作如果不指定基数 http://www.w3schools.com/jsref/jsref_parseint.asp

FYI, there are a few places that windows and javascript automatically decide that a number prefixed with a zero is octal and convert the number.

In windows if you ping and address like 10.0.2.010 it will actually ping 10.0.2.8

Windows also does this if you enter it as the ip/dns address for the computer

Though it is deprecated, Javascript does this by default on some functions like parseInt if you do not specify a radix http://www.w3schools.com/jsref/jsref_parseint.asp

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文