Recruit numbers to any base
Project description
RebelBase
RebelBase is a Python package for working with numbers of any base.
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
n = Base3(42) # Represent decimal 42 in base 3
print("n: ", n) # "1120" (Decimal 42 == base 3 1120)
print("n + 1:", n + 1) # "1121" (Decimal 42 + 1 == base 3 1121)
print("n - 1:", n - 1) # "1112" (Decimal 42 - 1 == base 3 1112)
print("n / 2:", n / 2) # "210" (Decimal 42 / 2 == base 3 210)
print("n * 2:", n * 2) # "10010" (Decimal 42 * 1 == base 3 10010)
n = Base3("212") # Create the base 3 value 212
print(int(n)) # "23" (Base 3 212 == decimal 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")
n = Base5(42) # Represent decimal 42 in base 5
print("n: ", n) # "EOI" (Decimal 42 == base 5 EOI)
print("n + 1:", n + 1) # "EOO" (Decimal 42 + 1 == base 5 EOO)
print("n - 1:", n - 1) # "EOE" (Decimal 42 - 1 == base 5 EOE)
print("n / 2:", n / 2) # "UE" (Decimal 42 / 2 == base 5 UE)
print("n * 2:", n * 2) # "OEU" (Decimal 42 * 2 == base 5 OEU)
n = Base5("OOO") # Create the base 5 value OOO
print(int(n)) # "93" (Base 5 OOO == decimal 93)
A Number
can be created with optional zero support for any base.
Numbers can be initialised with their decimal value or string representation.
A ton of Python operations -- including addition, subtraction, floor and true division, multiplication, modulo and exponentiation -- work 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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for rebelbase-1.0.0a7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc7ddceb0e449e9a460bf4a6725fe37726b8611779ff03b1a4a5fc19db7dae5c |
|
MD5 | a2bfcf807d79e54d8b0e04f5c7485a89 |
|
BLAKE2b-256 | 7d33fde56790217c141601272dea1221285ec1900a5d80b5e7e85c9cdcccfe8f |