Octal is another number system which has no advantages over hex but is still met from time to time. Only a brief look will be offered here just to make sure that we have at least mentioned it.
In hex, we used binary bits in groups of four because 11112 adds up to 15 which is the value of the highest digit (F) in hex. In octal, we use groups of three bits. The highest value is now 1112 which is 7. Octal therefore has eight digits and counts from 0 to 7. The count proceeds:
0
1
2
3
4
5
6
7
There is no 8th digit so reset the count to 0 and put a 1 in the next column.
10
11
12
13
14
15
16
17
Now go straight to 20
20
etc.
No letters are involved and it is often not recognized as octal until we realize that none of the numbers involve the digits 8 or 9.
Conversions follow the same patterns as we have seen for hex.
Octal to denary: the column heading values are 84, 83, 82, 81, 80.
Denary to octaclass="underline" divide by 8 and write down the remainder then read remainders from the bottom upwards. Use the subscript 8 to indicate an octal number, e.g. 6410=1008.
Octal to binary: write each octal digit down as a three digit binary group.
Binary to octaclass="underline" start from the right-hand side and chop the binary numbers into groups of three, then evaluate each group.
I think that is enough for octal. It’s (fairly) unlikely you will meet it again so we can say ‘goodbye Octal’.
In each case, choose the best option.
1 Which of these represents the largest number?
(a) 10008
(b) 100010
(c) 10002
(d) 1000H
2 The number CD02H is equal to:
(a) 5248210
(b) 5422810
(c) 5632210
(d) 5284210
3 The base of a number system is:
(a) always the same as the highest digit used in the system.
(b) usually +5 or +3.3.
(c) equal to the number of different digits used in the system.
(d) one less than the highest single digit number in the system.
4 Which of these numbers is the same as 101101110102:
(a) 164610
(b) 5BA16
(c) AB5H
(d) B72h
5 The number of digits in a denary number is often:
(a) more than the number of digits in the equivalent binary number.
(b) less than or equal to the number of digits in the equivalent hex number.
(c) more than the number of digits in the equivalent hex number.
(d) more than the number of digits in the equivalent decimal number.
4. How micros calculate
In the last chapter, we saw how numbers could be represented in binary and hex forms. Whether we think of a number as hex or binary or indeed denary, inside the microprocessor it is only binary. The whole concept of hex is just to make life easier for us.
We may sit at a keyboard and enter a hex (or denary) number but the first job of any microprocessor-based system is to convert it to binary. All the arithmetic is done in binary and its last job is to convert it back to hex (or denary) just to keep us smiling.
There was a time when we had to enter binary and get raw binary answers but thankfully, those times have gone. Everything was definitely NOT better in the ‘good old days’.
The form binary numbers take inside of the microprocessor depends on the system design and the work of the software programmers. We will take a look at the alternatives, starting with negative numbers.
In real life, it is easy, we just put a – symbol in front of the number and it is negative so +4 becomes –4. Easy, but we don’t have any way of putting a minus sign inside the microprocessor. We have tried several ways round the problem.
The first attempt seemed easy but it was false optimism. All we had to do was to use the first bit (msb) of the number to indicate the sign 1 = minus, 0 = plus.
This had two drawbacks.
1 It used up one of the bits so an 8-bit word could now only hold seven bits to represent numbers and one bit to say ‘plus’ or ‘minus’. The seven bits can now only count up to 11111112=127 whereas the eight bits should count to 255.
2 If we added two binary numbers like +127 and +2, we would get:
The msb (most significant bit) of 1 means it is a minus number and the actual number is 0000001=1. So the final result of +127+2 is not 129 but minus 1.
When we use a microprocessor to handle arithmetic with these problems, we can ensure that the microprocessor can recognize this type of accidental negative number. We can arrange for the microprocessor to compensate for it but it is rather complicated and slow.
Luckily, a better system came along which has stood the test of time, having been used for many years.
This has two significant advantages:
1 It allows the full number of bits to be used for a number so an 8-bit word can count from 0 to 111111112 or 255.
2 It is easy to implement with addition and subtraction using substantially the same circuitry.
So, how do we manage to use all eight bits for numbers yet still be able to designate a number positive or negative?
That’s clever. We will start by looking at positive numbers first because it is so easy. All positive numbers from 0 to 255 are the same as we get by simply converting denary to binary numbers. So that’s done.
Example
Add 01011010 + 00011011.
The steps are just the same as in ‘normal’ denary arithmetic. Step 1 Lay them out and start from the lsb (least significant bit) or right-hand bit
Add the right-hand column and we have 0+1=1. So we have
Step 2 Next we add the two 1s in the next column. This results in 2, or 10 in binary. Put the 0 in the answer box and carry the 1 forward to the next column
Step 3 The next column is easy 0+0+1=1
Step 4 The next line is like the second column, 1+1=10. This is written as an answer of 0 and the 1 is carried forward to the next column
Step 5 We now have 1 in each row and a 1 carried forward so the next column is 1+1+1=3 or 11 in binary. This is an answer of 1 and a 1 carried forward to the next column
Step 6 The next column is 0 + 0 + 1 = 1, and the next is 1 + 0 = 1 and the final bit or msb is 0 + 0 = 0, so we can complete the sum
Here is a question to think about: What number could we add to 50 to give an answer of 27? In mathematical terms this would be written as 50+x=27.
What number could x represent? Surely, anything we add to 50 must make the number larger unless it is a negative number like –23:
50 + (–23) = 27
The amazing thing is that there is a number that can have the same effect as a negative number, even though it has no minus sign in front of it. It is called a ‘two’s complement’ number.
Our sum now becomes:
50 + (the two’s complement of 23) = 27