In this article, we will learn about the conversion of binary to Gray code and vice versa. You can refer to the gray code table, where we have already shown the gray codes of 3-bit numbers, that is, the decimal numbers from 0 to 7. In this article, we will learn the conversion techniques so that you can convert from binary to Gray or vice versa for any bit length.
Conversion from Binary to Gray Code
The following steps are followed to convert a binary number to a corresponding Gray code.
- The most significant bit (left-most) in the Gray code is the same as the corresponding MSB in the binary number.
-
Going from left to right, add each adjacent pair of binary code bits to get the next Grey code bit. Discard carry.
Example: Convert the binary number 101110 to Gray code
Solution:
So, the final Gray code is 1011102 = 111001Gray
Learn about other code conversions:
Conversion from Gray Code to Binary
The following steps are followed to convert a Gray code to a corresponding binary number.
- The most significant bit (left-most) in the binary code is the same as the corresponding MSB in the Gray code.
-
Add each binary code bit generated to the Gray code bit in the next adjacent position. Discard carries.
Example: Convert the Grey code 111001 to binary number
Solution:
So, the final binary number is 111001Gray = 1011102
Previous Table of Content Next