八进制数字文字:什么时候?为什么?曾经?

时间:2020-03-05 18:47:51  来源:igfitidea点击:

我从未在代码中使用过八进制数字,也从未遇到过使用过八进制数字的任何代码(尽管有十六进制和bit twiddling)。

我大约在1994年开始使用C / C ++进行编程,所以也许对此我还太年轻?旧代码是否使用八进制? C通过在前面加上0来包括对这些字符的支持,但是使用这些基数为8的数字文字的代码在哪里?

解决方案

回答

它在Unix领域对chmodmkdir函数很有用,但是除此之外,我无法想到其他任何常用用法。

回答

来自维基百科

At the time when octal originally
  became widely used in computing,
  systems such as the IBM mainframes
  employed 24-bit (or 36-bit) words.
  Octal was an ideal abbreviation of
  binary for these machines because
  eight (or twelve) digits could
  concisely display an entire machine
  word (each octal digit covering three
  binary digits). It also cut costs by
  allowing Nixie tubes, seven-segment
  displays, and calculators to be used
  for the operator consoles; where
  binary displays were too complex to
  use, decimal displays needed complex
  hardware to convert radixes, and
  hexadecimal displays needed to display
  letters. 
  
  All modern computing
  platforms, however, use 16-, 32-, or
  64-bit words, with eight bits making
  up a byte. On such systems three octal
  digits would be required, with the
  most significant octal digit
  inelegantly representing only two
  binary digits (and in a series the
  same octal digit would represent one
  binary digit from the next byte).
  Hence hexadecimal is more commonly
  used in programming languages today,
  since a hexadecimal digit covers four
  binary digits and all modern computing
  platforms have machine words that are
  evenly divisible by four. Some
  platforms with a power-of-two word
  size still have instruction subwords
  that are more easily understood if
  displayed in octal; this includes the
  PDP-11. The modern-day ubiquitous x86
  architecture belongs to this category
  as well, but octal is almost never
  used on this platform.

-亚当

回答

最近,我不得不编写访问3位字段的网络协议代码。当我们要调试八进制时,它很有用。

仅出于效果,我们能告诉我这是3位字段吗?

0x492492

另一方面,八进制中的这个相同的数字:

022222222

现在,最后,以二进制形式(以3为一组):

010 010 010 010 010 010 010 010

回答

这些天,我遇到的唯一八进制文字是在Linux中处理文件的权限位时,通常将其表示为3个八进制数字,其中每个数字分别代表文件所有者,组和其他用户的许可。

例如0755(对于大多数命令行工具也只有755)意味着文件所有者具有完全权限(读取,写入,执行),而组和其他用户仅具有读取和执行权限。

以八进制表示这些位可以更轻松地确定设置了哪些权限。我们可以一目了然地知道0755是什么意思,但不知道493或者0x1ed。

回答

我是通过PDP-11与Octal接触的,因此,显然C语言是:)

回答

我还看到八进制在飞机应答器中使用。模式3a应答器代码是一个12位数字,每个人都将其视为4个八进制数字。有关Wikipedia的更多信息。我知道这通常与计算机无关,但是FAA也使用计算机:)。

回答

商用航空在古老的Arinc 429总线标准中使用八进制"标签"(基本上是消息类型ID)。因此,在为航空电子应用程序编写代码时,能够以八进制指定标签值非常好...

回答

从60年代和70年代末开始,仍然有许多旧的过程控制系统(Honeywell H4400,H45000等)被安排使用带有八进制寻址的24位字。考虑一下美国最近建造核电站的时间。

更换这些工业系统是一项相当艰巨的任务,因此,我们可能很幸运地在野外遇到一个巨大的定制浮点格式,然后在它们灭绝并惊叹之前,很幸运地遇到了一个!

回答

tar文件将信息存储为八进制整数值字符串

回答

I have never used octal numbers in my
  code nor come across any code that
  used it.

我敢打赌你有。根据标准,以零开头的数字文字是八进制的。琐碎地包括" 0"。每次我们使用或者看到字面的零时,它都是八进制的。奇怪但真实。 :-)

回答

学会使用PDP-8编程的任何人都对八进制数字怀有极大的热情。字长为12位,分为4组,每组3位,所以-1是8777八进制。该方案在具有16位字的PDP-11中得到了延续,但在各种事物上仍使用八进制表示,因此* NIX文件许可方案一直存在到今天。