Skip to main content

No project description provided

Project description

gatepy

made-with-python PyPI license PyPI version shields.io PyPI pyversions

gatepy is a Python implementation of a logical gate.

Installation

Open console and run the following command:

pip install gatepy

Done.

Examples

Adder

import gatepy


def adder(a, b):
    c = False
    a = list(format(a, "064b"))[::-1]
    b = list(format(b, "064b"))[::-1]
    out = []
    for i in range(64):
        S = int(
            gatepy.XOR(
                gatepy.XOR(int(a[i]), int(b[i])), c
            )
        )
        c = gatepy.OR(
            gatepy.AND(
                gatepy.XOR(int(a[i]), int(b[i])), c
            ),
            gatepy.AND(int(a[i]), int(b[i])),
        )
        out.append(str(S))
    return int("".join(out[::-1]), 2)


print(adder(1, 2))

Return:

3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gatepy-1.0.2.tar.gz (3.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page