skillfed

graycode

Convert two's complement integer to gray code and vice versa

graycode v1.0.5 97.8K downloads/30d#13,127 on PyPI
Permissive license Abandoned released

What it is and what it does

Graycode is a small utility library for converting between standard two's complement integers and gray code (reflected binary code), a binary numeral system where consecutive values differ by exactly one bit. This property makes gray codes useful in applications where bit transitions need to be minimized, such as digital electronics, error correction, and certain optimization problems.

The library provides three main functions: conversion from integers to gray code, conversion from gray code back to integers, and generation of all n-bit gray codes in sequence. It has no external dependencies and works with Python 3.5 and later. However, the package has been abandoned since late 2020 and receives no maintenance or updates.

Use it for:

  • Digital circuit design where minimizing bit transitions reduces power consumption or glitches.
  • Rotary encoder applications where gray code naturally represents mechanical position changes.
  • Error detection and correction systems that exploit the single-bit-change property.
  • Algorithm development or teaching that requires gray code sequences or conversions.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Converts between two's complement integers and gray code (reflected binary code), where successive values differ by only one bit.

Yes, if you need gray code conversion for a stable, self-contained use case. The library is small, dependency-free, and has no known vulnerabilities. However, the abandoned maintenance status means no bug fixes or Python version updates are forthcoming—install only if the current functionality meets your needs and you can maintain a local fork if necessary.

Install

graycode on PyPI

pip

pip install graycode

uv

uv add graycode

poetry

poetry add graycode

Installing graycode

Before you install

High install friction due to source distribution format. Package is abandoned (last release November 2020, over 5 years ago) with no maintenance activity, though it has no runtime dependencies.

License in practice

MIT license permits commercial and private use with minimal restrictions, requiring only license and copyright notice retention.

Quickstart

pip install graycode

import graycode

# Convert integer to gray code
graycode.tc_to_gray_code(5)

# Convert gray code back to integer
graycode.gray_code_to_tc(0b110)

# Generate all n-bit gray codes
graycode.gen_gray_codes(3)

Requires Python 3.5 or later; source distribution may require a C compiler on some systems.

Verify before relying

  • Whether the source distribution requires compilation or has platform-specific build requirements.
  • Current state of the GitLab repository and whether it accepts contributions or bug reports.

Package facts

License not declared (permissive)
Python support supports the current Python release (>=3.5)
Install friction high — source build required
Runtime dependencies none
Maintenance abandoned — 2,104 days since the last release
First released
Downloads 97,771/month — #13,127 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: graycode-1.0.5.tar.gz

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3

Tags

gray code conversionreflected binary codebit manipulationinteger to gray codegray code generator
bit-manipulationencoding

More Mathematics packages