{{ result.output }}
- {{ char }}
ℹ️ About Gray Code Converter
Gray code is an ordering of binary values where adjacent entries differ by one bit. The variant used by this converter is the binary-reflected Gray code described in Frank Gray's Pulse Code Communication patent; the NIST Dictionary of Algorithms and Data Structures notes the same one-bit transition property and its use in mechanical encoders.
This matters when a sensor, counter, or sampling circuit can be read while it is moving from one state to the next. In normal binary, a change such as 0111 to 1000 flips four bits, so a partially read transition can look like a very different value. In Gray code, each neighboring step changes only one bit, reducing transition ambiguity in rotary encoders, position sensors, ADC coding masks, Karnaugh maps, and clock-domain crossing counters.
Conversion examples:
1010binary becomes1111Gray code: keep the first bit, then XOR each binary bit with the bit before it.1111Gray code becomes1010binary: keep the first bit, then XOR each Gray bit with the binary bit already recovered.- The selected bit width pads with leading zeros for display and step analysis; it does not change the numeric value of the input.
Formula used by this tool:
- Binary → Gray: the most significant bit is copied; every following Gray bit is the XOR of the current binary bit and the previous binary bit.
- Gray → Binary: the most significant bit is copied; every following binary bit is the XOR of the current Gray bit and the previous recovered binary bit.
- Limitations: input must be a string of
0and1characters. This is a converter, not an error-correcting code, checksum, encryption method, or validator for every possible Gray-code variant.
API Usage Example:
POST /api/tools/conversion/gray-code
Content-Type: application/json
{
"mode": "binary-to-gray",
"input": "1010",
"bitWidth": 8
}