开发者

In what situations is octal base used?

I've seen binary and hex used quite often but never octal.开发者_如何学C 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?


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.


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


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.


Didn't think of this but Digital displays!

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


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).


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.


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜