Skip to main content

A purepython bit manager

Project description

bitman

What is bitman?

This is a pure python module for managing and manipulating an array of bits.

How does it work?

bitman takes advantage of python's ability to handle big integers. The array of bits is simply an integer with its bit values set as desired.

The array of bits is a class called bitman.

Attributes of bitman

  • size: It is an integer that holds the array size.
  • set(n, val): A function that sets the n-th bit to val.
  • get(n): A function that returns the truth value of the n-th bit.
  • which(val): A list of positions with a value val (0 or 1).

Installation

Please check https://pypi.org/project/bitman/ for the installable version.

You should be able to install with

pip install bitman

A quick tutorial

>>> from bitman import bitman  	# import the bitman class
>>> a = bitman(size=5,init=1)  	# 'a' is now a bitman instance with 5 bits, all initialized to 1
>>> print(a)			# printing 'a' returns the string of bits as in a binary number
11111
>>> a				# simply typing 'a' at the command line also returns the bits in the same order
11111
>>> a.get(2)			# get the truth value of the bit at position 2
True
>>> a.set(0, 0)			# set the bit at position 0 to 0.
>>> a
11110
>>> a.set(2, 0)			# set the bit at position 2 to 0.
>>> a
11010
>>> a.get(2)			# the second bit has been set to False
False
>>> a.get(3)			# the third bit is still True
True
>>> a.which(0)			# list of bits in a that are 0 
[0, 2]
>>> a.which(1)			# list of bits in a that are 1
[1, 3, 4]
>>> a.size			# how many bits are to be represented by a?
5
>>> a
11010
>>> a.size=8			# let us resize the array
>>> a
00011010

Invitation

You are welcome to improve bitman and suggest improvements.

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

bitman-1.0.3.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

bitman-1.0.3-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file bitman-1.0.3.tar.gz.

File metadata

  • Download URL: bitman-1.0.3.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for bitman-1.0.3.tar.gz
Algorithm Hash digest
SHA256 59a782e455f228487044262c036a70fafab380e84f769d00823120472e862416
MD5 0179f95208ba5985625f837a329cca0f
BLAKE2b-256 edff1dca0829539c44e1476e3e8844b529d39c18e2d5205eef036732cd93c54a

See more details on using hashes here.

File details

Details for the file bitman-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: bitman-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for bitman-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b29663783ced7a0906e97229c42f58a2625114c6682aad9e56825bc57c9a3ae6
MD5 c7552c0fd985ac076a9947e88ff9b335
BLAKE2b-256 88f069d45e9f26629b825132e457779d7f45216e266b04ce951dbd1b7d230444

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