Hi,
Someones signiture (the "real programmers
get confused as Oct 31 = Dec 25") reminded
me about Octal.
I have heard of it, and know it's still used
on the Calculator program on Windoze (2K),
And on many of my HP calculators.
on the computers at work, but unlike Hex,
Dec and Binary I have no idea what it could
be used for, and why it would still be used
today. Anyone care to fill in the gaps, please?
Here goes...
As I am sure you know, octal is simply base 8 notation.
And (most) computers use a binary code internally. The problem with
binary for humans, though, is the long strings of digits that are
involved -- think of writing down 32 0's and 1's for a longoword, and
being sure you've not missed one, or got them in the wrong order.
Now, since 8 is a power of 2 (=2^3), it's very easy to convert between
octal and binary. You know how to convert a binary number to hex, right,
by spliting the digits up into groups of 4 and converting each block of 4
bitd to hex. Well, you can do the same to convert a binary number to
octal, just split the digits up in groups of 3.
For example, consider 10101111.
To conver to hex, split it up into 4 bit groups
1010 1111
Convert each group
1010 -> A
1111 -> F
So the hex equivalent is AF
Now to convert it into octal, split it into groups of 3 bits
10 101 111
Convert each group
10 -> 2
101 -> 5
111 -> 7
So it's 257 in octal.
Advantage of octal (over hex) include :
You only need the digits 0-7. At one time there was considerable
resistance to using letters as digits, a second-hand book I bought last
week thinkks it's most unsatisfactory to do this.
Some machine codes (PDP8, PDP11, and to a lesser extent 8080) are easier
for humas to decode if written in octal. For example, the PDP11
instruction to copy R1 into R2 is (IIRC) 010102 in octal. You can decode
that by hand -- from the left
01 -> It's a move
0 -> Source addressing mode = register (not indirect or indexed, or...)
1 -> Source register = R1
0 -> Destination addressing mode = register
2 -> Sestination regstier =R2
Since the addressing mode and register select fields are all 3 bits long,
they correspond to individual octal digits in the octal form of the
instruction,. If you wrote it in hex, you'd not be able to pick out the
fields so quickly.
Disadvantage to octal over hex include ;
The numbers are longer (a 16 bit word takes 6 octal digits but only 4 hex
digits)
Word lengths tend not to be multiples of 3 bits. This means, for example you
can't easily split 16 bit word into bytes, or combine 2 bytes into a word
when you write them in Octal. In hex it's trivial. There were various
split octal notations where you convert each part separately, but they
get confusing fast.
But basically it's just another way of writing numbers which is useful
sometiimes (particularly if 'you're misisng 2 fingers' as Tom Lehrer put it.
-tony