Skip to content

Gray Code to Decimal Converter

Convert Gray code (reflected binary code) directly to decimal numbers for position sensors, rotary encoders, and absolute encoder readouts

Category: data
Use Case: Position Sensors, Encoder Values, Numeric Readouts
Privacy: 100% browser-based

Conversion Options

Quick reference:
Gray 0→0, 1→1, 11→2, 10→3, 110→4, 111→5, 101→6, 100→7
Gray 1100→8, 1101→9, 1111→10, 1110→11

Recommended Settings

Pro Tips

  • Gray code to decimal: first convert Gray→Binary, then Binary→Decimal
  • Conversion uses progressive XOR: each binary bit = XOR of all Gray bits up to that position
  • Common in position sensors where you need numeric position values directly
  • Gray code 0,1,11,10,110,111,101,100 = decimal 0,1,2,3,4,5,6,7

Most Popular

Most users output decimal values directly without showing binary intermediate step

When to Use This Tool

Absolute Position Sensor Readouts

Convert Gray code from absolute encoders and multi-turn encoders directly to numeric position values. Essential for CNC machines, robotics, and servo systems where you need the actual position number (0-1023, 0-4095, etc.) for control algorithms and feedback loops.

Rotary Encoder Position Display

Display numeric position values from rotary encoders in user interfaces, HMI screens, and monitoring systems. Convert Gray code encoder output to decimal for real-time position display on dashboards, control panels, and data logging applications.

Motor Control & Servo Systems

Process encoder feedback in motor control applications where numeric position is needed for PID controllers, motion profiles, and trajectory planning. Convert Gray code position data to decimal for real-time control loops in industrial drives and servo amplifiers.

Data Analysis & Calibration

Analyze encoder data during calibration, testing, and troubleshooting. Convert recorded Gray code sequences to decimal for data analysis in spreadsheets, plotting position vs time graphs, and verifying encoder accuracy. Useful for quality control and system diagnostics.

How It Works

1

Parse input Gray code strings (binary strings containing only 0s and 1s)

2

Remove whitespace and optional 0b prefix from each Gray code value

3

Validate that input contains only valid binary digits

4

Convert Gray code to binary: first bit unchanged, then XOR each Gray bit with previous binary bit

5

Convert resulting binary string to decimal using parseInt(binary, 2)

6

Format output with selected delimiter (newline, space, comma, or tab)

7

Optionally show conversion steps: Gray → Binary → Decimal

100% Private

Files never leave your device. All processing happens locally in your browser.

Lightning Fast

Powered by Pure JavaScript for optimal performance on modern browsers.

Secure

No data collection, no tracking, no sign-up required.

Frequently Asked Questions

What's the difference between Gray Code to Binary and Gray Code to Decimal?

Both perform the same Gray→Binary conversion internally, but Gray to Decimal adds a final step: converting binary to decimal (base-10 number). This tool is optimized for getting numeric position values directly, while Gray to Binary is better when you need the binary representation for further binary operations or bit manipulation.

Why do I get different decimal values from the same length Gray codes?

Gray code represents the same range as binary with the same number of bits. 3-bit Gray code (000-100) represents decimal 0-7. Leading zeros matter: Gray 110 (3-bit) = decimal 4, but Gray 0110 (4-bit) would also be decimal 4. The bit width determines the maximum value, not the decimal result for a given pattern.

How do I know what my encoder's Gray code values mean?

Check your encoder's datasheet for resolution (bits). An 8-bit encoder outputs 0-255 (256 positions), 10-bit gives 0-1023 (1024 positions), 12-bit gives 0-4095 (4096 positions). The Gray code output directly maps to these position numbers after conversion. Divide by max value to get rotation angle: position/1024 × 360° for a 10-bit encoder.

Can I use this for multi-turn absolute encoders?

Yes, but multi-turn encoders typically have separate Gray code outputs for turns (revolutions) and position within turn. You'll need to convert both separately: turns Gray code → decimal turns, position Gray code → decimal position. Then calculate: total_position = (turns × positions_per_turn) + position. Check your encoder manual for bit allocation.

What if I have hexadecimal Gray code from a datasheet?

First convert hexadecimal to binary, then use this tool. For example, hex 0x6 = binary 0110 (Gray code). Many datasheets show Gray code in hex for compactness. Use a hex-to-binary converter first, or read the datasheet's conversion table to get the decimal position value directly.

Why show conversion steps (Gray → Binary → Decimal)?

The 'Show conversion steps' option is useful for learning, debugging, and verification. It displays the intermediate binary value so you can verify the conversion is correct, understand how the algorithm works, and troubleshoot encoder issues. For production use, disable it to get clean decimal output.