Convert between radices and perform arithmetic.
Project description
radix-ops
Convert numbers - both integer and floating-point - from one base to another. Perform arithmetic operations in a given base.
Installation
pip install radix-ops
Usage
from radix import Num
a = Num(20, 16) # The number 20 in base 16
b = Num('ff', 16) # FF or 255 in base 16
print(a.to(2)) # Convert to base 2 (100000)
print(a + b) # Result in base 16 (11F)
Examples
>>> from radix import Num
>>> Num(value='FE', base=16).to(base=10)
254
>>> Num(1100, 2).to(10)
12
>>> Num(10.75).to(16) # When base is 10, it can be omitted.
A.C
>>> Num(10.75).to(2)
1010.11
>>> pi = 3.141592653589793
>>> Num(pi).to(16)
3.243F6A8885
>>> Num(-1001, 2).to(10)
-9
>>> (Num('1a', 16) - Num('ff', 16)) * Num(2, 16) # (26 - 255) * 2 = -458 = -0x1ca
-1CA
Note
- Base should be between 2 and 36.
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 Distribution
radix-ops-0.0.2.tar.gz
(3.4 kB
view hashes)
Built Distribution
Close
Hashes for radix_ops-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14e986e9e01896547086eeabf6c9857f49493a2f97d12db61acb4c467eea212b |
|
MD5 | 5e6f981e8f6540e9220501b1802198ac |
|
BLAKE2b-256 | 501eeac0aaf6c6c12a4d59ca4385820b2d8d72a919929b65dbee825e3f97a668 |