Octal/hexadecimal to binary conversion
Octal and hexadecimal conversion is
very simple. Each octal/hexadecimal digit is taken in turn and converted to its
binary representation according to the table above.
Example 9.3
Convert the octal number 7654 to
binary.
Solution
Using the table above, write down the
binary equivalent of each octal digit:
| 7 | 6 | 5 | 4 |
|111|110|101|100|
Thus, the binary code is 111110101100.
Example 9.4
Convert the hexadecimal number ABCD
to binary.
Solution
Using the table above, write down the
binary equivalent of each hexadecimal digit:
| A | B
| C | D
|
| 1010 | 1011 |
1100 | 1101 |
Thus, the binary code is
1010101111001101.
Binary to octal/hexadecimal
conversion
Conversion from binary to octal or
hexadecimal is also simple. The binary digits are taken in groups of three at a
time (for octal) or four at a time (for hexadecimal), starting at the least
significant end of the number (right-hand side) and writing down the
appropriate octal or hexadecimal digit for each group.
Example 9.5
Convert the binary number
010111011001 into octal and hexadecimal.
Solution
|
010 | 111 | 011 | 001 |
| 2 | 7 | 3 | 1 |
= 2731 octal
| 0101
| 1101 | 1001 |
|
5 | D | 9 |
= 5D9 hexadecimal
Example 9.6
The 24-bit binary number 011111001001001101011010
is to be entered into a computer. How would it be entered using (a) octal code
and (b) hexadecimal code?
Solution
(a) Divide the 24-bit number into
groups of three, starting at the right-hand side:
011 | 111 | 001 | 001 | 001 | 101 |
011 | 010 | = 37111532 octal
Thus, the number would be entered as
37111532 using octal code.
(b) Divide the 24-bit number into
groups of four, starting at the right-hand side:
| 0111 | 1100 | 1001 | 0011 | 0101 |
1010 | = 7C935A hexadecimal
In carrying out such conversions, it
is essential that the groupings of binary digits start from the right-hand
side. Groupings starting at the left-hand side give completely wrong values
unless the number of binary digits happens to be an integer multiple of the grouping
size. Consider a 10-digit binary number: 1011100011.
Grouping digits starting at the
right-hand side gives the values 1343 octal and 2E3 hexadecimal.
Grouping digits starting at the left
gives the (incorrect) values of 5611 octal and B83 hexadecimal.
When converting a binary number to
octal or hexadecimal representation, a check must also be made that all of the
binary digits represent data. In some systems, the first (left-hand) digit is
used as a sign bit and the last (right-hand) digit is used as a parity bit.
Example 9.7
In a system that uses the first bit
as a sign bit and the last bit as a parity bit, what is the octal and
hexadecimal representation of the binary code: 110111000111?
Solution
The ten data bits are 1011100011.
This converts to 1343 octal and 2E3 hexadecimal.
Programming and program execution
In most modes of usage, including use
as part of intelligent devices, computers are involved in manipulating data.
This requires data values to be input, processed and output according to a sequence
of operations defined by the computer program. However, in practice,
programming the microprocessor within an intelligent device is not normally the
province of the instrument user, indeed, there is rarely any provision for the
user to create or modify operating programs even if he/she wished to do so.
There are several reasons for this. Firstly, the signal processing needed
within an intelligent device is usually well defined, and therefore it is more
efficient for a manufacturer to produce this rather than to have each
individual user produce near identical programs separately. Secondly, better
program integrity and instrument operation is achieved if a standard program
produced by the instrument manufacturer is used. Finally, use of a standard program
allows it to be burnt into ROM, thereby protecting it from any failure of the
instrument power supply. This also facilitates software maintenance and
updates, by the mechanism of the manufacturer providing a new ROM that simply
plugs into the slot previously occupied by the old ROM.
However, even though it is not
normally a task undertaken by the user, some appreciation of microprocessor
programming for an intelligent device is useful background knowledge. To
illustrate the techniques involved in programming, consider a very simple
program that reads in a value from a sensor, adds a pre-stored value to it to
compensate for a bias in the sensor measurement, and outputs a corrected
reading to a display device.
Let us assume that the addresses of
the sensor and output display device are 00C0 and 00C1 respectively, and that
the required scaling value has already been stored in memory address 0100. The
instructions below are formed from the instruction set for a Z80Ł
microprocessor and make use of CPU registers A and B.
IN A,C0
IN B,100
ADD A,B
OUT C1,A
This list of four instructions
constitutes the computer program that is necessary to execute the required
task. The CPU normally executes the instructions one at a time, starting at the
top of the list and working downwards (though jump and branch instructions
change this order). The first instruction (IN A,C0) reads in a value from the
sensor at address C0 and places the value in CPU register A (often called the
accumulator). The mechanics of the execution of this instruction consist of the
CPU putting the required address C0 on the address bus and then putting a
command on the control bus that causes the contents of the target address (C0)
to be copied onto the data bus and subsequently transferred into the A
register. The next instruction (IN B,100) reads in a value from address 100
(the pre-stored biasing value) and stores it in register B. The following
instruction (ADD A,B) adds together the contents of registers A and B and
stores the result in register A. Register A now contains the measurement read
from the sensor but corrected for bias. The final instruction (OUT C1,A)
transfers the contents of register A to the output device on address C1.
No comments:
Post a Comment
Tell your requirements and How this blog helped you.