Binary 1011 → Gray — Gray code

introXOR each bit with the one above it

Answer

1110

Why this example is worth doing

The conversion rule in one line: keep the most significant bit, then XOR each remaining bit with its left-hand neighbour. The tool draws the XOR arrows between bit positions so the dependency chain is visible, and gives the algebraic form G = B ⊕ (B >> 1), which is how it is implemented in hardware — a row of XOR gates with no carry chain, so the conversion takes one gate delay regardless of width.

Try your own input in the Gray code. Convert binary to reflected Gray code and back, and build the sequence by reflection.

How the answer is reached

Binary 1011 to Gray code

Each Gray bit is the XOR of the binary bit and the binary bit above it.

Binary 1011 to Gray code — columns bit i, b_i, b_(i+1), g_i = b_i XOR b_(i+1)
bit ib_ib_(i+1)g_i = b_i XOR b_(i+1)
310 (nothing above the MSB)1
2011
1101
0110

binary1011

Gray1110

whole-word formG = B XOR (B >> 1) = 1011 XOR 0101 = 1110

Warning:

This is the binary reflected Gray code. It is one Gray code among many: any single-bit-change ordering of the codewords is a Gray code, and other constructions give different tables.

Source: Frank Gray, US Patent 2,632,058, "Pulse Code Communication" (filed 1947, granted 1953)

Compare with

Open this example in the Gray code

The field arrives filled in with this example’s input.

Note:

Notation this page assumes

  • Bit strings are written most significant bit first, and bit 0 is the least significant bit.
  • A width is stated explicitly wherever it changes the answer; nothing is silently sign-extended or truncated.
  • Gray code here is the reflected binary code, generated by reflection, with the least significant bit changing first.

Sources

  • Gray, “Pulse Code Communication”, US Patent 2,632,058 (1953)