Zero Signup ToolsFree browser tools

Developer Tools

Gray Code Converter

Convert decimal or binary to Gray code and decode Gray code back to binary in your browser. Selectable bit width, clickable bits, and XOR steps.

Bit width

Enter a non-negative integer. The tool reads it as standard binary, then encodes Gray code.

Bit pattern (standard binary)

Click a bit to flip it.

Standard binary

0010 1010

Gray code

0011 1111

Decimal

42

Hexadecimal (binary / Gray)

0x2A / 0x3F

Step by step

  1. Step 1: Standard binary

    0010 1010

  2. Step 2: Shift right by 1 (binary >> 1)

    0001 0101

  3. Step 3: XOR the two rows (binary XOR shifted)

    0011 1111 = Gray code

Encoding XORs the value with itself shifted right by one. Only one output bit changes when the input increases by one, which is the defining property of Gray code.

How to use

  1. Pick a bit width: 4, 8, 16, 32, or 64 bits. The output is zero-padded to that width.
  2. Choose a direction: Decimal to Gray, Binary to Gray, or Gray to binary.
  3. Type a value in the matching format. Decimal accepts plain digits; binary and Gray accept a 0 and 1 string with an optional 0b prefix.
  4. Read the standard binary, Gray code, decimal, and hexadecimal results, then copy whichever one you need.
  5. Click any bit in the live bit row to flip it, or open the step list to follow the XOR operations behind the conversion.

About this tool

Gray Code Converter translates numbers between standard binary, decimal, and Gray code, the reflected binary code in which any two successive values differ in exactly one bit. That single-bit-change property is the whole point of Gray code: when a value is read off a physical rotary or linear encoder, a mechanical counter, or any system where several bits change as a quantity increments, ordinary binary can momentarily show a wrong value while multiple bits flip at slightly different instants (for example 0111 to 1000 flips all four bits at once). Gray code guarantees only one bit ever changes between neighbors, so a transient misread can be off by at most one step instead of an arbitrary amount. The same property makes Gray code the natural ordering for the rows and columns of a Karnaugh map, where adjacent cells must differ in one variable, and it appears in error-correcting schemes, digital communications, and the bit strings used by some genetic algorithms. This tool runs three conversions, all with exact BigInt math so even the 64-bit width never loses precision. Decimal to Gray reads a non-negative integer as standard binary and encodes it. Binary to Gray takes a raw bit string and encodes it. Gray to binary decodes a Gray-code bit string back to standard binary and decimal. Encoding uses the compact identity gray = binary XOR (binary shifted right by one), and decoding folds the Gray bits with a running XOR from the most significant bit downward, so each output bit is the parity of every Gray bit at or above its position. You pick a bit width of 4, 8, 16, 32, or 64 bits, and the result is shown as the standard binary pattern, the Gray-code pattern (both grouped into nibbles for readability), the decimal value, and the hexadecimal value, each with its own copy button. A live bit row lets you click any bit to flip it and watch the other representation update, which is a fast way to see the one-bit-apart relationship for yourself, and a step list spells out the exact XOR operations so you can check the conversion by hand or use it to follow a homework problem. Everything is computed in your browser; nothing you enter is uploaded.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsDeveloper Tools