how to do binary to gray code conversion and vise versa

http://www.dspguru.com/comp.dsp/tricks/alg/grayconv.htm

encoder & decoder, k-map

To perform binary to Gray code conversion and vice versa, you need to understand the concept of Gray code and the conversion process. Here's how you can do it:

Binary to Gray Code Conversion:
1. Write down the given binary number. For example, let's consider the binary number as 10110.
2. The leftmost bit of the Gray code is the same as the leftmost bit of the binary number.
3. For the remaining bits, perform the XOR operation between each bit of the binary number and its previous bit (excluding the leftmost bit). Starting from left to right, XOR each bit with the previous bit and write down the result.
For example, using the given binary number 10110:
- The leftmost bit remains the same: 1.
- XOR the second bit (0) with the leftmost bit (1): 1 XOR 0 = 1.
- XOR the third bit (1) with the second bit (0): 1 XOR 0 = 1.
- XOR the fourth bit (1) with the third bit (1): 1 XOR 1 = 0.
- XOR the fifth bit (0) with the fourth bit (1): 0 XOR 1 = 1.
4. Write down the resulting bits from the XOR operation as the final Gray code. Using the above example, the Gray code for the binary number 10110 is 11011.

Gray Code to Binary Conversion:
1. Write down the given Gray code. For example, consider the Gray code as 11011.
2. The leftmost bit of the binary number will be the same as the leftmost bit of the Gray code.
3. For the remaining bits, perform the XOR operation between each bit of the Gray code and the corresponding bit of the previously calculated binary number (excluding the leftmost bit). Starting from left to right, XOR each bit with the corresponding bit and write down the result.
For example, using the given Gray code 11011:
- The leftmost bit remains the same: 1.
- XOR the second bit (1) with the leftmost bit (1): 1 XOR 1 = 0.
- XOR the third bit (0) with the second bit (0): 0 XOR 0 = 0.
- XOR the fourth bit (1) with the third bit (0): 1 XOR 0 = 1.
- XOR the fifth bit (1) with the fourth bit (1): 1 XOR 1 = 0.
4. Write down the resulting bits from the XOR operation as the final binary number. Using the above example, the binary number for the Gray code 11011 is 10010.

By following these steps, you can perform binary to Gray code conversion and vice versa.