graycode
Convert two's complement integer to gray code and vice versa
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 graycodeuv
uv add graycodepoetry
poetry add graycodeInstalling 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
Tags
More Mathematics packages
NetworkX provides data structures and…
permissive · top 1,000 on PyPI
kiwisolverkiwisolver is a Python binding to a fast C++…
permissive · top 1,000 on PyPI
sympySymPy is a Python library for symbolic…
permissive · top 1,000 on PyPI
contourpyContourPy calculates contours of 2D…
permissive · top 1,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
onnxruntimeonnxruntime loads and executes Open Neural…
permissive · top 1,000 on PyPI
bitarrayProvides an efficient C-backed array type for…
permissive · top 1,000 on PyPI
bitarray-hardbyteProvides an efficient C-backed array type for…
permissive · top 15,000 on PyPI
fixedintProvides fixed-width integer classes that…
permissive · top 5,000 on PyPI
macaddressParses, validates, and converts MAC addresses…
permissive · top 15,000 on PyPI
category-encodersTransforms categorical variables into numeric…
permissive · top 5,000 on PyPI
roman-numerals-pyConverts between integers and Roman numerals,…
permissive · top 5,000 on PyPI
hachoirHachoir parses and displays binary files as a…
copyleft · top 15,000 on PyPI
intbitsetintbitset provides a fast, memory-efficient set…
copyleft · top 15,000 on PyPI
blurhashEncodes images into compact blurhash text…
permissive · top 15,000 on PyPI
base36Converts integers to and from base36…
permissive · top 15,000 on PyPI