Chapter X: Binary Encoding Scheme

Section X.2 Non-Weighted Codes



Binary Encoding

Although the binary number system has many practical advantages and is widely used in digital computers, in many cases it is convenient to work with the decimal number system, especially when the communication between man and the machine is extensive since most numerical data generated by man are in terms of decimal numbers. To simplify the communication problem between man and machine, a number of codes have been devised so that the decimal digits are represented by sequences of binary digits.

Classification of binary codes


Nonweighted Codes

In this type of binary code, the positional weights are not assigned. The examples of non-weighted codes are Excess-3 code and Gray code.

Excess-3 code

The Excess-3 code is also called as XS-3 code. It is a non-weighted code used to express decimal numbers. The Excess-3 code words are derived from the 8421 BCD code words adding \( (0011)_2 \)or \( (3)_{10} \) to each code word in 8421. The excess-3 codes are obtained as follows :
The Excess-3 code is a binary-coded decimal (BCD) representation where each decimal digit is represented by its 4-bit binary equivalent plus 3. It is a self-complementary code used in digital systems for error detection and arithmetic operations. The 1's complement of the Excess-3 code aligns with the Excess-3 code of \(9-N\), which is why it's self-complementing.

Decimal Digit (N) Excess-3 Code (N+3) 1's Complement of Excess-3 Decimal 9's Complement (9-N) Excess-3 Code of 9-N
0 0011 1100 9 1100
1 0100 1011 8 1011
2 0101 1010 7 1010
3 0110 1001 6 1001
4 0111 1000 5 1000
5 1000 0111 4 0111
6 1001 0110 3 0110
7 1010 0101 2 0101
8 1011 0100 1 0100
9 1100 0011 0 0011

Excess-3 code Application


Gray Code

Gray code, also known as reflected binary code, is a type of binary numbering system where two successive values differ by only one bit.
It is a non-weighted code and it is not an arithmetic code. That means there are no specific weights assigned to the bit position. It has a very special feature that, only one bit will change each time the decimal number is incremented as shown in Fig X.1. As only one bit changes at a time, the gray code is called as a unit distance code.

The gray code is a cyclic code . The term "cyclic" in the context of Gray code means that the Gray code sequence forms a closed loop. The last value in the sequence transitions back to the first value, and this transition involves only a single-bit change, just like any other consecutive values in Gray code. Gray code cannot be used for arithmetic operations. In this code, two consecutive values are differed by one bit of binary digits.

Binary to Gray conversion :

  1. The Most Significant Bit (MSB) of the gray code is always equal to the MSB of the given binary code.
  2. Other bits of the output gray code can be obtained by XOR binary code bit at that index and previous index.
Note: XOR, short for "exclusive or", is a logical operation that returns true if the inputs are different, and false (or 0) if they are the same.

Gray to binary conversion :
  1. The Most Significant Bit (MSB) of the binary code is always equal to the MSB of the given gray code.
  2. Other bits of the output binary code can be obtained by checking the gray code bit at that index. If the current gray code bit is 0, then copy the previous binary code bit, else copy the invert of the previous binary code bit.
n-bit Gray Code Generating
The n-bit Gray code is a member of a class called reflected codes. The term ″reflected″ is used to designate codes which have the property that the n-bit code can be generated by reflecting the (n-1)st-bit code, as illustrated here (left to right is the 1 bit, the two bit, the three bit.

Steps:


Figure X.1


A four-bit Gray code is shown in the following table:

Decimal Binary Gray Code
000000000
100010001
200100011
300110010
401000110
501010111
601100101
701110100
810001100
910011101
1010101111
1110111110
1211001010
1311011011
1411101001
1511111000


Key Characteristics:

Gray code Application

Rotary Encoders: Gray code is commonly employed in rotary encoders, which are used in various devices like robotics, industrial control systems, and navigation systems. It ensures accurate tracking of rotational position by encoding the position values in Gray code, where only one bit changes at a time. This property helps to prevent errors or glitches during the position tracking process.

Example: 3-Bit Gray Code Rotary Encoder

Imagine a rotary encoder divided into \(2^3=8\) positions. These positions are encoded using 3-bit Gray code:

Position Gray Code Binary Code (for comparison)
0000000
1001001
2011010
3010011
4110100
5111101
6101110
7100111


Explanation:

Reference

BCD Code
Binary Codes
Gray to Binary and Binary to Gray conversion
Gray Code