Gray 1110 → binary — Gray code

introcumulative XOR from the left

Answer

1011

Why this example is worth doing

The reverse conversion is not symmetric, and that asymmetry is the thing to notice. Each binary bit is the XOR of all Gray bits from the most significant down to that position, so the computation is a running total and each output depends on every input above it. In hardware that is a chain, not a row, so decoding is slower than encoding — a real consideration when the code is used at speed.

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

Gray code 1110 to binary

Copy the most significant bit, then XOR each Gray bit with the binary bit already produced above it. This direction is inherently sequential.

Gray code 1110 to binary — columns bit i, g_i, b_(i+1), b_i = b_(i+1) XOR g_i
bit ig_ib_(i+1)b_i = b_(i+1) XOR g_i
31- (the MSB is copied)1
2110
1101
0011

Gray1110

binary1011

equivalentlyb_i = parity of g_(n-1) ... g_i

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)