Productivity and Utilities

Gray Code Converter

Enter a decimal, binary or Gray code value to convert it and to see the full Gray code sequence.

Your numbers

Input is

Decimal digits, or a string of 0 and 1 for binary and Gray code, up to 64 bits. Example value.

More options

Shows the whole Gray sequence for this many bits, 1 to 6.

Result

Gray code

1111

Binary 1010, decimal 10.

Decimal value
10
Binary
1010
Gray code
1111
Gray code as a decimal number
15
Bits used
4

All 4-bit Gray codes

DecimalBinaryGray codeBit that changes
000000000-
100010001bit 0
200100011bit 1
300110010bit 0
401000110bit 2
501010111bit 0
601100101bit 1
701110100bit 0
810001100bit 3
910011101bit 0
1010101111bit 1
1110111110bit 0
1211001010bit 2
1311011011bit 0
1411101001bit 1
1511111000bit 0
How this was calculated
  1. Binary to Gray: each Gray bit is the binary bit XOR the binary bit to its left. In short, gray = n XOR (n shifted right by one) = 1010 XOR 0101 = 1111.
  2. Gray to binary: keep the first bit, then each binary bit is the previous binary bit XOR the current Gray bit. That gives 1010.
  3. In a Gray sequence only one bit changes between neighbors. That is why it is used where a reading may be caught between two positions, such as rotary encoders.

Calculated using SumPanda.com · https://sumpanda.com/gray-code-converter/

Results are estimates for general information. Verify important figures before relying on them.

Next step

How to use the gray code converter

  1. Choose what your input is: a decimal number, a binary number or a Gray code written as bits.
  2. Enter the value. Binary and Gray code can be up to 64 bits, and leading zeros are kept.
  3. Read the decimal value, the binary form and the Gray code, with the Gray code also as a decimal number.
  4. Choose a table width in the advanced options to see every Gray code for that number of bits and which bit changes at each step.

Formula

binary to Gray: gray = n XOR (n shifted right by 1)

Gray to binary: keep the first bit, then each binary bit = previous binary bit XOR the Gray bit

neighbors n and n + 1 differ in exactly one bit of their Gray codes

XOR gives 1 where two bits differ and 0 where they are the same. Gray code is also called reflected binary code.

The number 10 and a 4-bit table

Decimal 10 is 1010 in binary. Shifting right by one gives 0101, and 1010 XOR 0101 = 1111, so the Gray code of 10 is 1111. Going the other way, the Gray code 1111 gives binary 1010, which is decimal 10. The Gray code of 7 is 100, of 255 is 10000000 and of 12345 is 10100000100101.

The 4-bit sequence runs 0000, 0001, 0011, 0010, 0110, 0111, 0101, 0100, 1100, 1101, 1111, 1110, 1010, 1011, 1001, 1000. In the table, only one bit changes from each row to the next, and the last code differs from the first by a single bit as well. All of these were checked against a Python script.

Why Gray code is used

In ordinary binary, going from 3 to 4 changes three bits at once (011 to 100). If the bits are read by sensors that do not switch at exactly the same instant, a reading in between can be badly wrong. A Gray code changes one bit at a time, so any reading caught in the middle of a change is off by at most one step. That is why rotary encoders, position sensors and some counters use it.

Other uses and related tools

The same pattern appears in puzzles such as the Towers of Hanoi, in the order of cells in a Karnaugh map and in some error reduction schemes. For plain binary arithmetic, use the Binary Calculator, for the XOR and shift operations the Bitwise Calculator, and for other bases the Number Base Converter.

More tools for playing with numbers

For more number patterns and conversions, try the Digit Grouping Converter, Magic Square Generator and Pythagorean Triples Generator.

Assumptions and limits

  • The code is the standard reflected binary Gray code.
  • Binary and Gray inputs are strings of 0 and 1 of up to 64 bits, and decimal inputs have up to 20 digits.
  • Numbers are treated as unsigned, with no negative values.
  • The table covers 1 to 6 bits, which is up to 64 rows.
  • The value in the form is an example to replace with your own.

Formulas reviewed October 10, 2026. See the calculation methodology for how SumPanda rounds, tests and sources its formulas.

Frequently asked questions

Is there only one Gray code?

No. Any sequence where neighbors differ by a single bit is a Gray code. The reflected binary version is the one in common use, and it is the one this tool produces.

Why is it called reflected?

The sequence for n + 1 bits is the sequence for n bits, then the same sequence in reverse order with a leading 1. The second half is a mirror image of the first.

Can I add Gray codes directly?

Not simply. Convert to binary, do the arithmetic and convert back. The codes are useful for reading positions, not for adding.

What does the last column of the table show?

It shows which bit position changed compared with the row above, counted from 0 at the right. It is a way to check that exactly one bit changes at each step.