Wednesday 2 February 2022

Gray Code

 Gray Code

 

The Gray Code is a sequence of binary number systems, which is also known as reflected binary code. The reason for calling this code as reflected binary code is the first N/2 values compared with those of the last N/2 values in reverse order. In this code, two consecutive values are differed by one bit of binary digits. Gray codes are used in the general sequence of hardware-generated binary numbers. These numbers cause ambiguities or errors when the transition from one number to its successive is done. This code simply solves this problem by changing only one bit when the transition is between numbers is done.

The gray code is a very light weighted code because it doesn't depend on the value of the digit specified by the position. This code is also called a cyclic variable code as the transition of one value to its successive value carries a change of one bit only.


How to generate Gray code?

The prefix and reflect method are recursively used to generate the Gray code of a number. For generating gray code:


  1. We find the number of bits required to represent a number.
  2. Next, we find the code for 0, i.e., 0000, which is the same as binary.
  3. Now, we take the previous code, i.e., 0000, and change the most significant bit of it.
  4. We perform this process reclusively until all the codes are not uniquely identified.
  5. If by changing the most significant bit, we find the same code obtained previously, then the second most significant bit will be changed, and so on.







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




Popular Posts