Gray code, also known as reflected binary code, is a binary numeral system where two consecutive numbers differ in only one bit position. It is a non-weighted code, meaning that each bit position in the code does not represent a specific weight or value like in traditional binary codes.

Gray code is useful in applications where errors due to switching between two adjacent states must be minimized, such as in digital communications, digital signal processing, and analog-to-digital conversion. It is also used in mechanical and electronic devices for encoding angular positions.

In Gray code, each bit position represents a power of two, just like in traditional binary code. However, instead of adding or subtracting powers of two to get the decimal value of a number, in Gray code, each bit position is flipped based on the position of the previous bit.

**2-bit Gray code:**

Decimal Binary Gray Code

0 00 00

1 01 01

2 10 11

3 11 10

**3-bit Gray code:**

Decimal Binary Gray Code

0 000 000

1 001 001

2 010 011

3 011 010

4 100 110

5 101 111

6 110 101

7 111 100

4-bit Gray code:

Decimal Binary Gray Code

0 0000 0000

1 0001 0001

2 0010 0011

3 0011 0010

4 0100 0110

5 0101 0111

6 0110 0101

7 0111 0100

8 1000 1100

9 1001 1101

10 1010 1111

11 1011 1110

12 1100 1010

13 1101 1011

14 1110 1001

15 1111 1000