Skip to main content

A python module for manipulating positional integers across any numerical base, providing advanced digit-level control.

Project description

digint

Base-Agnostic Integer Manipulation

digint is a module focused on easy high-level integer manipulation across any numerical base. Works with binary, decimal, or any other base. digint seeks to make complex digit-level and notation operations easy, just like they were Collections.

Documentation

Setup

This module can be installed using:

pip install digint

Usage

This module is intended to be used only as a module, and can be imported after installing using the traditional process:

from digint import digitint

Create an integer in any base

# input integers as you would with `int()`,
# if the intiger is already in the base you wish to use
n1 = digitint(1234, base=10)
n2 = digitint("BASE36", base=36)
n3 = digitint(0xABCDEF, base=16)

# convert bases on initialization, if the input is a intiger type
n4 = digitint(255, base=2) # == 0b11111111
n5 = digitint(int("BASE36", 36), base=10) # == 683248722
n6 = digitint(0xABCDEF, base=10) # == 11259375

Access and modify digits like a collection

# get the digit at index 2
print(n1.get_digit(2)) # outputs "3"
num.set_digit(2, 5)
print(n1.get_digit(2)) # outputs "5"

Easy notation

print(str(n2)) # output "BASE36"
print(str(n3)) # output "ABCDEF"
print(str(n5)) # output "683248722", as the base is set to 10

Full mutable collection implementation on integers

print(n2.pop(-1)) #outputs "6"
print(n2.pop(-1)) #outputs "3"
n2.append(int("D", 36))
print(n2) #outputs "BASED"

# The sum of all digits
print(sum(n2)) #outputs "76"

# The average of all digits
print(sum(n2)/len(n2)) #outputs "15.2"

Customizable Notation

# same as str(n3) 
print(n3.notate()) # outputs "ABCDEF"

from digint import NotationFormat
fmt = NotationFormat(*tuple("0123456789ZYXWVU"))
print(n3.notate(fmt)) # outputs "ZYXWVU"

And More

There are a handfull of other ease of use features that this module provides, feel free to reference the documentation for more information.

Licence

This is licensed under the Mozilla Public License 2.0 (MPL 2.0) Licence. See the Licence file in this repository for more information.

Contribute

Contributions are always welcome! Use the github repository to report issues and contribute to this project.

Credits

While not required, feel free to credit "Markus Hammer" (or just "Markus") if you find this code or script useful for whatever you may be doing with it.

Security Policy

While the python source code will be actively maintained, any binary files (if at all provided) are in no way supported. These are provided as a courtesy and are not intended to be the main usage of this software. Please keep this in mind when choosing how you wish to use this software.

Supported Versions

Version Supported
1.0.0.0 >=
1.0.0.0 <

Reporting a Vulnerability

Please report any issues to the email 107761433+MarkusHammer(THEN THE @ SYMBOL HERE)users.noreply.github.com

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

digint-1.0.3.0.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

digint-1.0.3.0-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file digint-1.0.3.0.tar.gz.

File metadata

  • Download URL: digint-1.0.3.0.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for digint-1.0.3.0.tar.gz
Algorithm Hash digest
SHA256 03dbccda62ee7a22683c14dcdbf6f50debcba58ee045bfe6516c64e938bb8294
MD5 715306419bc1cb67a29af227773baefb
BLAKE2b-256 fd86e833cdfa17ddf246d4ed17347b0c01e0d640dd2f44b34b46105796101350

See more details on using hashes here.

File details

Details for the file digint-1.0.3.0-py3-none-any.whl.

File metadata

  • Download URL: digint-1.0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for digint-1.0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49fd1cc07678d96d859c8396846e345758d404f7b205b161937178a454470f2f
MD5 9db05ed278ac0ca1ad4f90e75ef0f08d
BLAKE2b-256 fffd659537ad8fa8e074ff962423ef8e6e975dfea51efc96c8c3d2ba574801cd

See more details on using hashes here.

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