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) # Decimal 42 == base 3 1120
print("n + 1:", n + 1) # Decimal 42 + 1 == base 3 1121
print("n - 1:", n - 1) # Decimal 42 - 1 == base 3 1112
print("n / 2:", n / 2) # Decimal 42 / 2 == base 3 210
print("n * 2:", n * 2) # Decimal 42 * 1 == base 3 10010
n = Base3("212") # Create the base 3 value 212
print(int(n)) # 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) # Decimal 42 == base 5 EOI
print("n + 1:", n + 1) # Decimal 42 + 1 == base 5 EOO
print("n - 1:", n - 1) # Decimal 42 - 1 == base 5 EOE
print("n / 2:", n / 2) # Decimal 42 / 2 == base 5 UE
print("n * 2:", n * 2) # Decimal 42 * 2 == base 5 OEU
n = Base5("OOO") # Create the base 5 value OOO
print(int(n)) # 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.
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.
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.0a5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba76f0772b77f1084b711ed33cd7cd39a42ce4e83aad9efbfa928ecc2e4d390e |
|
MD5 | 2a18851c366a01a0954621a9ec8ab073 |
|
BLAKE2b-256 | 32d0a2c9f5c21acc66d8b69c50db49a46aecd324981396cf0ff2120db6eccb23 |