Online Gray to Decimal Converter

When you have a Gray bit string and need its decimal value, you first have to decode it. The online Gray to Decimal Converter takes a Gray bit string and shows its unsigned base-10 value.

I’ll explain how Gray code relates to binary, then show how to use the converter.

TL;DR: Convert Gray Code to Decimal

Gray code 1101 decodes to binary 1001, which is decimal 9.

  • Copy the Gray bits in their original left-to-right order.
  • Keep the first bit, then XOR each following Gray bit with the previous decoded binary bit.
  • Read the resulting binary digits as a base-2 value and convert that value to base 10.

What Is Gray Code, and How Does It Relate to Binary?

Gray code assigns a bit string to each position in its sequence. Decoding changes that code word into an ordinary binary value. Gray input and ordinary binary use the same digits but assign them different meanings.

NIST describes Gray-code sequences with multiple forms at widths of four bits or more. Check which form the encoder or protocol specifies before decoding its readings.

Decimal positionBinaryThree-bit Gray code
0000000
1001001
2010011
3011010

For the common binary-reflected form, adjacent values differ in one bit. This is useful when a mechanical encoder moves between neighboring positions. Confirm the encoder’s code family before decoding its readings.

XOR, or exclusive OR, returns 1 when two input bits differ and 0 when they match. For Gray bits 1, 1, 0, 1, the decoded result is 1, 0, 0, 1.

How does binary 1001 become decimal 9?

The example table summarizes the decoded result. Use the same three-stage record for another input so a reviewer can tell whether a disagreement began in Gray decoding or decimal arithmetic.

CheckQuestionAction
SourceDoes this device use binary-reflected Gray code?Confirm the code family in its documentation
InputAre all characters bits, in the recorded order?Remove labels and separators before conversion
Decoded valueDoes the binary sequence match a prefix-XOR trace?Compare intermediate bits from left to right
Decimal valueDoes the binary place-value sum match?Evaluate only the decoded binary digits

This checklist separates encoding, transcription, decoding, and arithmetic checks. It is useful when the converter gives a value that seems inconsistent with an encoder display.

For Gray input 1101, the decoded binary value is 1001. Its place-value sum is 8 + 1 = 9.

StageValueMeaning
Gray input1101Encoded bit sequence
Decoded binary1001Ordinary base-2 digits
Decimal output9Base-10 value of binary 1001

I include the intermediate binary value in a check because it separates bit decoding from the base-10 arithmetic.

How to Use the Online Gray to Decimal Converter

The page provides the “Gray Code Input” and “Decimal Output” fields. The source also defines a Clear All control.

Step 1: Copy the Gray bit string

Copy the code word without changing its order. Compare the first and last bits with the original reading before entering it, especially if you copied it from a table or log.

Step 2: Enter the bits

Paste or type the sequence into the Gray Code Input box. The live page source trims whitespace at the beginning and end, then checks that every remaining character is a zero or one. Separators between bits are not documented as valid input.

Step 3: Convert and read the decimal value

Choose Convert to Decimal and read the value shown in Decimal Output. I ran a Python example separately on input 1101 to demonstrate a manual check.

aditya@codeforgeek:~$ python3 gray_to_decimal_demo.py
Gray:    1101
Binary:  1001
Decimal: 9

[exit 0]
Gray code 1101 decoded to binary 1001 and decimal 9

The output shows both the decoded bits and their base-10 value, so you can check the calculation in two stages. The example was run from a terminal rather than through the page form.

Step 4: Clear the fields before another value

Clear All empties both fields. This keeps an earlier decimal result from being mistaken for the result of a later bit string.

Common Input Errors and Numeric Limits

Check the accepted characters and the numeric range before using the decoded value. The page source trims outer whitespace and checks for a nonempty binary string, while JavaScript Number conversion can lose precision for large integers.

CaseSymptomCheck or fix
Empty inputFails the nonempty input checkConfirm that a bit string was copied
Letters, punctuation, or an internal separatorFails the character checkRemove extra characters and verify each bit
Whitespace at either endTrimmed before validationKeep any spacing outside the sequence
Leading zeroesUnsigned value stays the sameRetain the original width if a protocol needs it
Value above JavaScript’s safe integer rangeNumber may lose precisionUse an exact integer representation such as BigInt
Signed measurementConversion does not establish signednessCheck the producing device’s encoding convention

The page source’s validation details appear in the table. I did not test the form in a browser.

For example, the first decoded binary bit is copied from the first Gray bit. Each later decoded bit depends on the previous decoded bit, not the previous Gray bit, so keep those two columns separate while checking a longer reading.

A useful manual check is to compare adjacent decoded prefixes as they grow. If a Gray input has eight bits, write eight decoded bits in order and compare the final string with the converter result. A mismatch near the left edge changes all later prefix calculations, while a mismatch near the right edge affects fewer positions.

The three-bit table earlier shows one complete cycle of four values. Its Gray words are ordered so consecutive rows change one bit.

When a reading comes from a specification, preserve the original field width and any accompanying metadata. A decimal integer alone cannot tell a later reader whether omitted leading zeroes carried width information or whether the source applied a sensor calibration.

For a quick consistency check, decode the input first and then evaluate the binary place values. Gray 1101 becomes binary 1001, which evaluates to 1 × 8 + 0 × 4 + 0 × 2 + 1 × 1. This gives 9 without treating the Gray digits as ordinary binary weights.

Input validation and numeric precision are separate concerns. A string containing only zeroes and ones can pass character validation but still represent an integer too large for an exact JavaScript Number. For large fields, use arithmetic that retains each bit or constructs a BigInt rather than converting through an imprecise Number.

The binary digits and decimal answer do not identify the application’s measurement range or units. Check the device documentation before treating the number as a physical quantity.

Leading zeroes leave an unsigned value unchanged, but can preserve a fixed signal width. Keep them in the source record if another device or protocol requires that width.

MDN documents that JavaScript integer results outside the safe range, which ends at 9,007,199,254,740,991, may lose precision. For values above that limit, use a decoder that retains bits as BigInt or another exact integer type. See the MDN parseInt() reference.

Gray-to-binary conversion recovers the encoded bits but does not identify a signed measurement or its units. Check the source system’s convention before applying a sign, offset, or scale.

Conclusion: Decode the Bits Before Using the Number

Keep the original Gray word beside the decoded binary and decimal values so another reader can trace the conversion.

RecordWhy it helps
Original Gray bitsLets you compare the source reading with the conversion
Decoded binarySeparates Gray decoding from decimal arithmetic
Decimal value and source unitsConnects the integer to the device-defined meaning

For the formal Gray-code property, see the NIST Dictionary of Algorithms and Data Structures entry. The CMU Gray-code FAQ describes the inverse rule.

For the reverse direction, use CodeForGeek’s online decimal-to-Gray-code converter. Its decimal-to-BCD converter handles a different digit encoding.

FAQ

These answers clarify input formatting and the meaning of a decoded number.

Can I enter spaces between the bits?

The page source trims whitespace at the start and end, then accepts only 0 and 1. It does not establish that internal spaces are accepted.

Does Gray code convert directly to decimal?

Decode Gray code to ordinary binary with prefix XOR, then interpret the binary value in base 10.

Do leading zeroes change the decimal value?

Leading zeroes do not change an unsigned integer value, but may preserve a fixed bit width needed by your system.

Does Gray-to-decimal conversion define signedness?

No. Signedness comes from the source system’s encoding convention, not from the Gray-to-binary conversion itself.

Aditya Gupta
Aditya Gupta

Aditya Gupta is a founding member and editor at CodeForGeek. He first found his way into tech by reading articles, and now writes approachable guides to Node.js security, authentication, AI tools, coding agents, and web scraping.

Articles: 529