Gray Code to Decimal Converter

Decodes a Gray code value (entered as binary digits) back into ordinary binary bit by bit from the most significant bit, then converts that binary value to its decimal integer equivalent. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-27

Overview

Introduction

Gray code values need to be decoded back to ordinary binary before their numeric value can be read, since the reflected-binary reordering isn't a simple bit pattern you can read directly as base 2.

This tool reverses that reordering and reports the decimal integer a given Gray code value represents.

What Is Gray Code to Decimal Converter?

A converter that takes a Gray code (reflected binary code) value, written as binary digits, and decodes it back to the decimal integer it represents.

It performs the exact mathematical inverse of the Gray code encoding used by the Decimal to Gray Code Converter in this same category.

How Gray Code to Decimal Converter Works

The input is validated as a binary string, then decoded one bit at a time starting from the most significant bit: the first binary bit equals the first Gray bit, and each subsequent binary bit is the XOR of the previous decoded bit and the current Gray bit.

Once the full binary string has been reconstructed, it's parsed as a base-2 integer via BigInt and converted to a decimal string.

When To Use Gray Code to Decimal Converter

Use it to interpret a raw Gray code reading from a rotary or absolute position encoder as an ordinary decimal number.

It's also useful for verifying, bit by bit, how the Gray-to-binary decoding process reconstructs the original value.

Features

Advantages

  • Uses BigInt internally, so it isn't limited to 32-bit integers and can decode arbitrarily long Gray code values.
  • Applies the standard, well-known bit-by-bit Gray decoding algorithm directly, with no approximation.
  • Instant, deterministic, fully client-side.

Limitations

  • Only decodes unsigned Gray code values into non-negative decimal integers; there's no built-in handling for a signed Gray code convention.
  • Expects the input already expressed as binary digits (0s and 1s); it doesn't accept decimal or hex-formatted Gray code notations.

Examples

Decoding a 3-bit Gray code value

Input

111

Output

5

Bit by bit: binary bit 1 = 1, binary bit 2 = 1 XOR 1 = 0, binary bit 3 = 0 XOR 1 = 1, giving binary 101, which is 5.

Decoding a 4-bit Gray code value

Input

1111

Output

10

Bit by bit: 1, then 1 XOR 1 = 0, then 0 XOR 1 = 1, then 1 XOR 1 = 0, giving binary 1010, which is 10.

Best Practices & Notes

Best Practices

  • Cross-check a decoded result with the Decimal to Gray Code Converter by re-encoding the decimal output and confirming you get your original Gray code back.
  • Make sure you're entering the Gray code itself, not the plain binary equivalent of the decimal value, since the two look the same only for very small numbers.

Developer Notes

Implemented with a simple string-based bit-by-bit XOR pass to reconstruct the binary digits (`binaryBits[i] = binaryBits[i-1] === grayBits[i] ? "0" : "1"`), then `BigInt("0b" + binaryString)` to parse the reconstructed binary into a decimal value.

Gray Code to Decimal Converter Use Cases

  • Interpreting raw Gray code readings from rotary or absolute position encoders
  • Verifying Karnaugh map bit orderings against their decimal indices
  • Teaching how the bit-by-bit Gray-to-binary decoding algorithm reconstructs a value

Common Mistakes

  • Reading a Gray code string as if it were plain binary; the two only coincide for decimal values 0 through 2, and diverge from decimal 3 onward.
  • Decoding from the wrong end of the string; the algorithm must start from the most significant (leftmost) bit.

Tips

  • Round-trip a value through the Decimal to Gray Code Converter and back through this tool as a quick correctness check.
  • Decode consecutive Gray code values (differing by one bit) and confirm their decimal outputs are consecutive integers.

References

Frequently Asked Questions