# Gray Code and Thermometer BCD Encoder Visualizer

Convert an N-bit value to binary, Gray, one-hot and thermometer codes with a counting truth table, Hamming-distance chart and Verilog/VHDL encoder stubs.

> Canonical page: https://elysiatools.com/en/tools/gray-code-and-thermometer-bcd-encoder-visualizer

- **Category:** Development

- **Keywords:** gray code converter, thermometer code, one-hot encoding, hamming distance chart, binary to gray verilog, flash adc thermometer, async fifo gray pointer, unit distance code

## Overview

A digital-design visualizer for binary-code alternatives on words of 2–6 bits.

Encodings produced simultaneously for the chosen value: plain binary; Gray/reflected code (G = B XOR (B >> 1), the unit-distance code whose adjacent values — including the wrap — differ in exactly one bit); one-hot (2ⁿ bits, a single 1); and thermometer/unary (2ⁿ−1 bits, MSB-aligned, the native flash-ADC comparator output).

The Hamming-distance chart walks every counting transition and shows the hazard directly: binary flips up to all n bits at carry boundaries (0111→1000), Gray and thermometer never flip more than one bit, one-hot always flips exactly two. A full counting truth table doubles as the Karnaugh-map axis order and rotary-encoder disc pattern.

Ready-to-paste HDL stubs: parameterized Verilog and VHDL modules with binary→Gray (XOR), binary→one-hot (sized shift), binary→thermometer (MSB-aligned unary shift), and the Gray→binary cascading-XOR decoder.

## Inputs

- **Word Width (bits)** (select)
- **Input Value (decimal)** (number): 11
- **HDL Stub Language** (select)
- **Show Full Counting Sequence Table** (checkbox)

## When to use

- Designing asynchronous FIFO pointers or clock domain crossing logic that require unit-distance Gray codes to eliminate multi-bit sampling glitches.
- Modeling flash ADC comparator outputs and verifying thermometer-to-binary or thermometer-to-Gray encoder logic.
- Evaluating state machine encoding schemes to compare bit-switching activity and Hamming distances between binary, one-hot, and Gray implementations.

## How it works

- Select the word width between 2 and 6 bits and enter the decimal value to convert.
- Choose the desired HDL stub language (Verilog, VHDL, or both) and toggle the full counting sequence table option.
- Inspect the resulting binary, Gray, one-hot, and thermometer codes alongside transition bit flips, the Hamming-distance chart, and synthesizable HDL modules.

## Use cases

- Asynchronous FIFO pointer synchronizer design and verification.
- Flash ADC thermometer code conversion and decoder logic drafting.
- Rotary encoder disc layout mapping and unit-distance transition analysis.

## Frequently asked questions

### What word widths does the visualizer support?

The visualizer supports word widths from 2 bits (values 0–3) up to 6 bits (values 0–63).

### Why do Gray and thermometer codes prevent multi-bit switching hazards?

Adjacent values in Gray and thermometer codes differ by only one bit per step (Hamming distance of 1), preventing intermediate sampling errors at counter boundaries.

### How is binary converted to Gray code?

Binary values are converted to Gray code using the standard bitwise equation G = B XOR (B >> 1).

### What is the difference between one-hot and thermometer encoding?

One-hot sets exactly one active high bit across 2ⁿ bit positions, while thermometer code fills an MSB-aligned continuous run of 1s across 2ⁿ−1 bits.

### What HDL code templates are provided?

The tool outputs parameterized Verilog and VHDL modules for binary-to-Gray, binary-to-one-hot, binary-to-thermometer encoders, and cascading XOR Gray-to-binary decoders.

## Related tools

- [Tailwind Color Palette Sync](https://elysiatools.com/en/tools/tailwind-color-palette-sync): Generate theme.extend.colors for tailwind.config.ts from HEX colors, with WCAG contrast levels and optional dark mode.
- [Extended Text Base Codecs (Base65536 + netstring)](https://elysiatools.com/en/tools/extended-text-base-codecs): Encode and decode with less-common text codecs: Base65536 (binary → dense Unicode) and netstring (self-delimiting framing). Base85 is intentionally not rebuilt (already covered).
- [cURL to Go (net/http) Converter](https://elysiatools.com/en/tools/curl-to-go): Convert a cURL command into a Go net/http code snippet with http.NewRequest, headers, and body
- [cURL to JavaScript (axios) Converter](https://elysiatools.com/en/tools/curl-to-js-axios): Convert a cURL command into a JavaScript axios code snippet with config object, headers, and data
- [cURL to JavaScript (fetch) Converter](https://elysiatools.com/en/tools/curl-to-js-fetch): Convert a cURL command into a JavaScript fetch() code snippet with headers, body, and method
- [cURL to PHP (cURL) Converter](https://elysiatools.com/en/tools/curl-to-php): Convert a cURL command into a PHP cURL code snippet with curl_setopt, headers, and post fields
- [cURL to Python (requests) Converter](https://elysiatools.com/en/tools/curl-to-python): Convert a cURL command into a Python requests code snippet with headers, data, and method
- [Domain Extractor](https://elysiatools.com/en/tools/domain-extractor): Extract domain names from URLs. Supports various extraction options including subdomains and path analysis.

## Samples

- [QR Code Samples](https://elysiatools.com/en/samples/qrcode-samples): Sample QR code images for testing QR code reading and generation tools
- [Code Comment Samples](https://elysiatools.com/en/samples/code-comment-samples): Sample code files with various comment styles for testing comment removal
- [Web Image Processing Python Samples](https://elysiatools.com/en/samples/web-image-processing-python): Web Python image processing examples using PIL/Pillow including reading, saving, resizing, and format conversion
- [Code Viewer Samples](https://elysiatools.com/en/samples/code-viewer-samples): Sample long-tail code and config files (shell, Vue, C++, TOML, Graphviz) for the in-browser Code Viewer
