Gray Code Conversion Prof. Neeraj Bhargava Pooja Dixit Department of Computer Science, School of Engineering & System Sciences MDS University Ajmer, Rajasthan
What is Gray Code? Gray Code system is a binary number system in which two successive pair of numbers differs in only one bit. It is also known as Reflected binary code. (RBC) or Cyclic code. Binary no is converted to gray code to reduce switching operation. Today gray code are widely used to facilitate the error correction in digital communications such as cable TV system. It is unweighted code that means it does not depends on positional value of digit. It is also called unit distance code or minimum error code. It is used in applications in which the normal sequence of binary numbers generated by the hardware may produce an error or ambiguity during the transition from one number to the next. So, the Gray code can eliminate this problem easily since only one bit changes its value during any transition between two numbers.
Binary to Gray conversion Verify how two successive pair of numbers differs in only one bit. Now if we take an 3,4 decimal no as example and check how this number convert into binary and gray code. Now lets see how many bits are changing in case of binary number. So, here in binary conversion total 3 bits(b0,b1,b2) are changing while in gray code only 1 bit is changed. Decimal Binary Gray b3 b2 b1 b0 g3 g 2 g1 g0 3 0 1 1 0 1 0 4 1 0 0 1 1 0
Binary to Gray conversion Now if we take an 7,8 decimal no as example and check how this no convert into binary and gray code. Now lets see how many bits are changing in case of binary number. So, here in binary conversion total 4 bits(b0,b1,b2,b3) are changing while in gray code only 1 bit is changed. that’s why gray code is also called unit distance code or switching operation is reduced in gray code. Decimal Binary Gray b3 b2 b1 b0 g3 g 2 g1 g0 7 1 1 1 1 0 0 8 1 0 0 0 1 1 0 0
Binary to Gray conversion Step 1: Record the MSB as it is. Step 2: Add the MSB to the next bit, record the sum and neglect the carry. Step 3: Repeat the process Ex1: Convert 1 0 1 1 to Grey code. Solution: 1 0 1 1 1 1 1 0 MSB LSB + + + +
Binary to Gray conversion XOR Operation Note: in Gray code conversion MSB remain same. A B XOR 1 1 1 1 1 1
Gray to Binary conversion Step 1: Record the MSB as it is. Step 2: Add the MSB to the next bit of gray code, record the sum and neglect the carry. Step 3: Repeat the process Ex1: Convert 1 1 1 0 to Grey code. Solution: 1 1 1 0 1 0 1 1 MSB LSB + + + +