Skip to main content

Introduction

Gray code or reflected binary code (RBC) is an ordering of binary numbers such that two successive numbers only differ in one bit. In essence, this is an alternative to two's complement integers when it is useful to change only one bit between successive numbers.

This library implements functions to convert gray code to two's complement integer and vice versa.

See LICENSE.md for copyright information. This library is licensed under the MIT license.

See https://en.wikipedia.org/wiki/Gray_code for details and applications of gray codes.

Installation

$ python3 setup.py install

Or from PyPi:

$ pip3 install graycode

Example

import graycode

for i in range(8):
    print(i, '{:03b}'.format(graycode.tc_to_gray_code(i)))

=>

0 000
1 001
2 011
3 010
4 110
5 111
6 101
7 100

Reverse is also provided:

graycode.gray_code_to_tc(0b011)

=>

2

gen_gray_codes(n) produces all n bit gray codes:

graycode.gen_gray_codes(3)

=>

[0, 1, 3, 2, 6, 7, 5, 4]

Metadata

Release files for graycode 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graycode 1.0.5
File Size Uploaded Provenance Actions
graycode-1.0.5.tar.gz 3.8 kB Without provenance Details for graycode-1.0.5.tar.gz

Release files / graycode-1.0.5.tar.gz

Download URL graycode-1.0.5.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
43d4a79e7787c5aea89c554d2c462783af91cbb65ebb13284f519874145be0f8
BLAKE2b-256 checksum
How to use checksums
3bc17431f895ae3bc6c9554922bd1bb959b78138a348183332c7f22da1a32c1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

Security for graycode 1.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page