If an n bit binary number is represented by Bn Bn-1 ...B1 and its Gray code equivalent by Gn Gn-1...G1 where Bn and Gn are the most significant bits (MSBs), then the Gray code bits are obtained from the binary code as follows. The symbol ⊕ stands for the Exclusive OR (XOR) operation explained below.
The conversion procedure is as follows:
- Record the MSB of the binary as the MSB of the Gray code.
- Add the MSB of the binary to the next bit in binary, recording the sum and ignoring the carry, if any, i.e, XOR the bits. This sum is the next bit of the Gray code.
- Add the 2nd bit of the binary to the 3rd bit of the binary, the 3rd bit to the 4th bit and so on.
- Record the successive sums as the successive bits of the Gray code until all the bits of the binary number are exhausted.
EXAMPLE:
Convert the binary 1001 to Gray code.
Solution:
Two methods to convert binary to Gray code |
Method I:
As shown in (a) in image above, record the 8’s bit '1' (MSB) of the binary as the 8’s bit of the Gray code. Then add the 8’s bit of the binary to the 4's bit of the binary (1 + 0-1). Record the sum as the 4's bit of the Gray code. Add the 4's bit of the binary to the 2’s bit of the binary (0 + 0 = 0). Record the sum as the 2’s bit of the Gray code. Add the 2’s bit of the binary to the 1's bit of the binary (0 + 1 = 1). Record the sum as the 1's bit of the Gray code. The resultant Gray code is 1101.
Method II:
As shown in (b) in image above, write the given binary number and add it to the same number shifted one place to the right. Record the MSB of the binary, i.e. 1 as the MSB of the Gray code. Add the subsequent columns (0+1=1 ; 0+0=0 ; 1+0=1) and record the corresponding sum as the subsequent significant bits of the Gray code. Ignore the bit shifted out. The resultant Gray code is 1101.
No comments :
Post a Comment