GGraySorrel
Product

Product features · Fixed-width Gray code conversion

01

In GraySorrel, inspect the XOR conversion and inverse fold together, keeping numeric range separate from bit width.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Fixed-width Gray code conversion

● ● ●GraySorrel●
A concrete starting point · Fixed-width Gray code conversion ×
def checked_word(value, width):
    if type(width) is not int or not 1 <= width <= 16:
        raise ValueError("word.width")
    if type(value) is not int or not 0 <= value < (1 << width):
        raise ValueError("word.value")
    return value

def to_gray(value, width):
    value = checked_word(value, width)
    return value ^ (value >> 1)

def from_gray(value, width):
    value = checked_word(value, width)
    result = 0
    while value:
        result ^= value
        value >>= 1
    return result
✳Convert integer words to Gray code and back with an explicit width from one through 16 bits.
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗