3
3
The electronic digital systems like computers, microprocessors etc., are required
to process data which may include numbers, alphabets or special characters. The
binary system of representation is the most extensively used one in digital
systems i.e, digital data is represented, stored and processed as group of binary
digits (bits). Hence the numerals, alphabets, special characters and control
functions are to be converted into binary format. The process of conversion into
binary format is known as binary coding. Several binary codes have developed
over the years. Some of them are discussed in this section.
2. Gray code.
3. ASCII code
Input is done in decimal then converted to binary for internal processing. For
output, the result has to be converted from its internal binary representation to a
decimal form.
One commonly used code is the Binary Coded Decimal (BCD) code which
corresponds to the first 10 binary representations of the decimal digits 0-9. The
BCD code requires 4 bits to represent the 10 decimal digits. Since 4 bits may have
up to 16 different binary combinations, a total of 6 combinations will be unused
Table (1)
To illustrate the BCD code, take a decimal number such as 874. Each digit is
changed to its binary equivalent as follows:
ب
2- Gray Code
The gray code is un-weighted and is not an arithmetic code; that is, there are
no specific weights assigned to the bit positions. The important feature of the
Gray code is that it exhibits only a single bit change from one code number to the
next.
Table (2) is a listing of the four bit gray code for decimal numbers 0 through 15.
Notice the single bit change between successive gray code numbers. For instance,
in going from decimal 3 to decimal 4, the gray code changes from 0010 to 0110,
while the binary code changes from 0011 to 0100, a change of three bits. The
only bit change is in the third bit from the right in the gray code; the other remain
the same.
Binary Number to Gray Code Conversion:
Solution:
Step 1: the left-most Gray code digit is the same as the left-most binary code bit.
Step 2: add the left-most binary code bit to the adjacent one:
Step 4: add the next adjacent pair and discard the carry:
Step 5: add the last adjacent pair:
2- start from the MSB adding without carry each result binary bit with
the lower gray code bit
Solution:
Step 2: add the last binary code bit just generated to the gray code bit in the next position.
Discard the carry.
Step 3: add the last binary code bit generated to the next Gray code bit.
Step 4: add the last binary code bit generated to the next Gray code bit.
Step 5: add the last binary code bit generated to the next Gray code bit. discard
carry.