Digital Codes: Binary-to-Gray Code Conversion: Conversion Between Binary Code and Gray Code Is
Digital Codes: Binary-to-Gray Code Conversion: Conversion Between Binary Code and Gray Code Is
Digital Codes: Binary-to-Gray Code Conversion: Conversion Between Binary Code and Gray Code Is
Many specialized codes are used in digital systems. You have just learned about the
BCD code; now let's look at a few others. Some codes are strictly numeric, like BCD,
and others are alphanumeric; that is, they are used to represent numbers, letters,
symbols, and instructions. The codes introduced in this section are the Gray code and
the ASCII 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 word to the next in sequence. This
property is important in many applications, such as shaft position encoders, where error
susceptibility increases with the number of bit changes between adjacent numbers in a
sequence.
.
Binary-to-Gray Code Conversion: Conversion between binary code and Gray code is
sometimes useful. The following rules explain how to convert from a binary number to
a Gray code word:
1. The most significant bit (left-most) in the Gray code is the same as the corresponding
MSB in the binary number.
2. Going from left to right, add each adjacent pair of binary code bits to get the next
Gray code bit. Discard carries.
For example, the conversion of the binary number 10110 to Gray code is as follows:
1
Gray-to-Binary Conversion: To convert from Gray code to binary, use a similar
method; however, there are some differences. The following rules apply:
1. The most significant bit (left-most) in the binary code is the same as the
corresponding bit in the Gray code.
2. Add each binary code bit generated to the Gray code bit in the next adjacent position.
Discard carries.
For example, the conversion of the Gray code word 11011 to binary is as follows:
Alphanumeric Codes
In order to communicate, you need not only numbers, but also letters and other symbols.
In the strictest sense, alphanumeric codes are codes that represent numbers and
alphabetic characters (letters). Most such codes, however, also represent other
characters such as symbols and various instructions necessary for conveying
information.
At a minimum, an alphanumeric code must represent 10 decimal digits and 26 letters of
the alphabet, for a total of 36 items. This number requires six bits in each code combina-
tion because five bits are insufficient (2 5 = 32). There are 64 total combinations of six
bits. so there are 28 unused code combinations. Obviously. in many applications,
symbols other than just numbers and letters are necessary to communicate completely.
You need spaces, periods, colons, semicolons, question marks, etc. You also need
instructions to tell the receiving system what to do with the information. With codes that
are six bits long, you can handle decimal numbers, the alphabet, and 28 other symbols.
This should give you an idea of the requirements for a basic alphanumeric code. The
ASCII is the most common alphanumeric code and is covered neXt.
ASCII
ASCII is the abbreviation for American Standard Code for Information Interchange.
Pronounced "askee," ASCII is a universally accepted alphanumeric code used in most
computers and other electronic equipment. Most computer keyboards are standardized
2
with the ASCII. When you enter a letter. a number, or control command. the
corresponding ASCII code goes into the computer.
ASCII has 128 characters and symbols represented by a 7-bit binary code. Actuall),
ASCII can be considered an 8-bit code with the MSB always O. This 8-bit code is 00
through 7F in hexadecimal. The first thirty-two ASCII characters are non graphic
commands that are never printed or displayed and are used only for control purposes.
Examples of the control characters are ""null," "line feed," "start of text," and "escape."
The other characters are graphic symbols that can be printed or displayed and include
the letters of the alphabet (lowercase and uppercase). the ten decimal digits, punctuation
signs and other commonly used symbols.
Table 1 is a listing of the ASCII code showing the decimal, hexadecimal, and binary
representations for each character and symbol. The left section of the table lists the
names of the 32 control characters (00 through IF hexadecimal). The graphic symbols
are listed in the rest of the table (20 through 7F hexadecimal).
The ASCII Control Characters: The first thirty-two codes in the ASCII table (Table1)
represent the control characters. These are used to allow devices such as a computer and
printer to communicate with each other when passing information and data. Table 2 lists
the control characters and the control key function that allows them to be entered
directly from an ASCII keyboard by pressing the control key (CTRL) and the
corresponding symbol. A brief description of each control character is also given.
In addition to the 128 standard ASCII characters, there are an additional 128 characters
that were adopted by IBM for use in their PCs (personal computers). Because of the
popularity of the PC, these particular extended ASCII characters are also used in
applications other than PCs and have become essentially an unofficial standard.
The extended ASCII characters are represented by an 8-bit code series from hexadeci-
mal 80 to hexadecimal FE
3
4
5
6