Skip to main content

Recruit numbers to any base

Project description

RebelBase

codecov

RebelBase is a Python package for working with numbers of different bases.

Full documentation is online at rebelbase.dev.

What does RebelBase do?

Want to work with base 3 numbers? We've got you covered.

from rebelbase import Base3

# Create the base 3 value of decimal 42:
n = Base3(42)

print("n:    ", n)      #  1120
print("n + 1:", n + 1)  #  1121
print("n - 1:", n - 1)  #  1112
print("n / 2:", n / 2)  #   210
print("n * 2:", n * 2)  # 10010

# Create the base 3 value 212:
n = Base3("212")

print(int(n))           #    23

Need to make your own bonkers base 5 system with vowels for digits? No problem.

from rebelbase.number import Number

class Base5(Number):
    @classmethod
    def digits(cls) -> tuple[str, ...]:
        return ("A", "E", "I", "O", "U")

# Create the base 5 value of decimal 42:
n = Base5(42)

print("n:    ", n)      # EOI
print("n + 1:", n + 1)  # EOO
print("n - 1:", n - 1)  # EOE
print("n / 2:", n / 2)  #  UE
print("n * 2:", n * 2)  # OEU

# Create the base 5 value OOO:
n = Base5("OOO")

print(int(n))           #  93

A rebelbase.Number can be created with optional zero support for any base.

Numbers can be initialised with their decimal value or string representation.

Support for a ton of Python operations -- including addition, subtraction, floor and true division, multiplication, modulo and exponentiation -- works out of the box.

Installation

RebelBase requires Python 3.9 or later.

pip install rebelbase

Support

Please raise bugs, request new features and ask questions at github.com/cariad/rebelbase/issues.

Contributions

See CONTRIBUTING.md for contribution guidelines.

In a nutshell: bugs and feature requests are gratefully received at github.com/cariad/rebelbase/issues and I don't accept unplanned pull requests.

The Project

RebelBase is © 2022 Cariad Eccleston and released under the MIT License at cariad/rebelbase.

The Author

Hello! 👋 I'm Cariad Eccleston and I'm a freelance backend and infrastructure engineer in the United Kingdom. You can find me at cariad.earth, github.com/cariad, linkedin.com/in/cariad and on Mastodon at @cariad@tech.lgbt.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

rebelbase-1.0.0a4-py3-none-any.whl (8.3 kB view hashes)

Uploaded Python 3

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