conversion_gray_code
Convert binary to Gray code or Gray code back to binary using XOR between adjacent bits. Minimize errors in rotary encoders, ADC, and Karnaugh maps.
Instructions
Gray Code Converter (Reflected Binary). Convert a binary number to Gray code (reflected binary code) or a Gray code back to plain binary, using XOR between adjacent bits. Gray code is an ordering where only one bit changes between consecutive values, which minimizes errors in rotary encoders, analog-to-digital conversion, and Karnaugh maps. Use conversion_binary_decimal for plain base-2/decimal conversion or conversion_bcd for binary-coded decimal. Runs locally on the bit string you provide: read-only, non-destructive, offline, and rate-limited (60 requests/min anonymous). Returns the converted bit string, its decimal value, the Gray decimal value, an explanation, step-by-step XOR working, and bit properties.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mode | Yes | Conversion direction. binary-to-gray treats input as plain binary and emits Gray code; gray-to-binary treats input as Gray code and emits plain binary. | |
| input | Yes | The bit string to convert, digits 0 and 1 only. Left-padded with zeros to bitWidth; must not exceed bitWidth digits. | |
| bitWidth | No | Fixed width in bits the input is zero-padded to (1-32). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| success | No | Whether the conversion succeeded. | |
| result | No | The Gray code conversion result. |