Free Online Utility • Binary Studio • Base-2 Engine

Convert Gray Code to Binary

Decode reflected binary Gray code back into standard weighted binary numbers with cumulative XOR derivation.

Formula & Quick Reference Base-2 Engine
B[n-1] = G[n-1];  B[i] = B[i+1] XOR G[i]
Or parallel: B ^= (B >> 1) ^ (B >> 2) ^ (B >> 4)...
0011 (Gray)0010 (Bin = 2)
0110 (Gray)0100 (Bin = 4)
1111101010101100 (172)
GRAY CODE TO BINARY
Standard Binary Output

        
100% client-side exact Binary Engine Instant

Session Calculation Log

No entries recorded in this session yet.

How Convert Gray Code to Binary Works

Convert Gray Code to Binary decodes reflected binary Gray code back into standard weighted binary integers using exact prefix-XOR propagation.

Binary arithmetic and base-2 encoding form the physical foundation of digital microprocessors, network packets, memory buffers, and cryptographic primitives. Every calculation in this utility runs directly inside your browser using exact JavaScript BigInt and typed-array pipelines, so arbitrary-length bitstreams, 128-bit addresses, and raw byte buffers never suffer from 53-bit IEEE floating-point truncation or server latency.

Cumulative Prefix-XOR Algorithm

B[MSB] = G[MSB]
For i = MSB-1 down to 0: B[i] = B[i+1] XOR G[i]

Using logarithmic shift-XOR doubling (`b ^= b >> 1; b ^= b >> 2; b ^= b >> 4; ...`), even 256-bit Gray codes decode in O(log W) steps.

Worked Reference Examples

InputOutputStep / Bit Note
00110010Decimal 2
01100100Decimal 4
1111101010101100Decimal 172 (0xAC)

Practical Engineering Applications

Position Sensor Decoding

Convert Gray code output from absolute rotary encoders into linear angle values.

Karnaugh Map Simplification

Map Gray-ordered K-map coordinates back into standard binary minterm indices.

Precision, Edge Cases & Best Practices

Preserves exact input bit width by default and supports batch multi-line Gray decoding.

All input parsing strips harmless formatting whitespace, underscores, or common prefixes such as 0b where applicable, while preserving exact bit order and padding width so outputs drop straight into C/C++, Rust, Verilog, VHDL, Python, and embedded firmware test harnesses.

Frequently Asked Questions

How do you convert Gray code back to binary manually?
Keep the leftmost bit identical, then XOR each previously recovered binary bit with the next Gray bit to its right.
Is Gray-to-binary conversion reversible?
Yes — Gray encoding is a bijection on every n-bit space, so decoding always recovers the exact original binary integer.
Does this preserve leading zeros?
Yes, Auto mode maintains the exact bit width of your input Gray string.