views:

196

answers:

9

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?

+3  A: 

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.

Matti Virkkunen
+4  A: 

Didn't think of this but Digital displays!

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

zaf
+7  A: 

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

Thomas
But since the values only go from 0-7, isnt it technically the same as Decimal or Hexidecimal?
Neil N
No, because in decimal you'd also have 8 and 9, and so on.
Matti Virkkunen
@Neil no, because those would give you different numerical values -- `0x755` is `011101010101` in binary, whereas `0755` is `111101101`. The former, then, would mean something completely different in unix file permissions.
SamB
Ahh, I was thinking each digit was applied seperately. "755" of course is very different than its decimal counterpart.
Neil N
+5  A: 

Octal is used when your word consists of a number of bits divisible by 3: Ancient systems with 18bit word sizes, unix file permissions.

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

ndim
+1 for providing the (IMHO) best answer so far.
stakx
A: 

Octal is an invention by super-villains everywhere in an attempt to confuse programmers and obfuscate code. I believe the first originator of the concept was doc oct(al) in his fight with spiderman in Amazing Spider-Man #3 (July 1963).

Either that or just so that someone could have the following joke in their signature line:

why do programmers confuse christmas with halloween?

because dec25 == oct31

yamspog
+2  A: 

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

Stephen C. Steel
A: 

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

EddieC
Anything that uses Windows Sockets [`inet_addr()`](http://msdn.microsoft.com/en-us/library/ms738563%28v=VS.85%29.aspx) will exhibit this documented behaviour.
Brian Nixon
A: 

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

richardtallent
.... What? One "traditional" (i.e. on piano) octave has 12 sounds. 12. Not 7. And you can't avoid sharps and flats in anything even remotely serious.
SigTerm
There are 12 notes on the chromatic scale, but only 7 on the diatonic scale. Musical notes are labeled according to the diatonic scale, A-G, which is an octal numbering system. Solfège also travels the diatonic scale. True, the other 5 semitones in between require additional marks to represent, but the OP asked about *uses* of octal numbering, NOT information theory, where of course representing music would require more than 3 bits per note.
richardtallent
A: 

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

Brian Nixon