array based binary counters with useful functions attached
Project description
BinaryCounters
an Array-based binary counter with functions designed for cellular automata experimentation
INSTALL INSTRUCTION
pip install BinaryCounters
how to use:
BinaryCounter(<int>=val,<int>=bitLength)
FUNCTIONS:
-
these are the logical gates - AND,NAND,OR,XOR,XNOR,NOR,NOT.
-
they are included for convinence - and can be used anywhere an 'arbitray function' can be used (they fit the requirments of having the inputs i,bit1,bit2, and give a 0/1 as the output).
-
note: these are not meant for anything other than binary, these are not meant to be called, but to be passed into a method as an argument.
METHODS
KEEP_EVEN(<bool>=increaseBool):
-
increase bool determines if number increases or decreases
-
forces an even number by shifting value by 1
KEEP_ODD(<bool>=increaseBool):
-
increase bool determines if number increases or decreases
-
forces an even number by shifting value by 1
SORT_B(<bool>=fromSig):
SECTION(<int>=start,<int>=stop):
SPAWN(<int>=start,<int>=stop):
COUNT(<bool>=willCountOnes):
-
willCountOnes if true, this function will return number of 1's, otherwise it will return the number of 0's
SHIFT_UP( <int>=amount):
SHIFT_DOWN( <int>=amount):
SHIFT_CIRCLE( <int>=amount, <bool>=dir):
-
dir determines rotational direction. If True:
-
rotates the binary by an amount = 1: (0,0,0,1)=>(1,0,0,0) amount = 2: (0,0,0,1)=>(0,1,0,0)
-
If False:
-
rotates the binary by an amount = 1: (1,1,0,1)=>(1,0,1,1) amount = 2: (1,1,1,0)=>(1,0,1,1)
BIT_OP( <BinaryCounter>=binary, <str>=operator):
-
operator options are = "XOR","OR","AND","NAND,"XNOR","NOR","NOT"
-
binary must be the same length as owner of method.
INCREASE(<int>=amount):
-
amount must be a positive integer, or results in no change
-
amount will not increase set bits, it will max at all 1's
DECREASE(<int>=amount):
-
amount must be a positive integer, or results in no change
-
amount will not wrap around in value, it will end at all 0's
COUNT(<bool>=countOnes):
READ():
SIZE():
GET_MAX():
SET_BIT_LENGTH(<int>=len):
B_TO_I(<int>[]=bin):
VAL():
BIN():
SET_V(<int>=value):
GET_BIN_OF(<int>=b):
-
b is calculated into an array of zero's and one's that represent it's binary, with a leading significant digit
SET_BIT(<int>=val,<int>=pos)
W_BIT_OP(<BinaryCounter>=binary, <Function>=fn):
-
WRAPPED BIT OPERATION: the second array is looped over if it is smaller than the method's owner
-
binary may be a different length from the owner of this method
-
this method iterates though and modifys its binary by running a fn on it, and the the matching index of the binary
-
note that this wraps around the binary you supply, so it may be of any length.
S_BIT_OP(<BinaryCounter>=binary, <Function>=fn):
-
STATIONARY BIT OPERATION: there is no wrap lke in W_BIT_OP, if the binary you pass in has a smaller bitLength, S_BIT_OP will operate from smallest significant digit to largest, and return the original binary when it runs of of the binary you pass in.
-
binary may be a different length from the owner of this method
-
this method iterates though and modifys its binary by running a fn on it, and the the matching index of the binary
-
note that this wraps around the binary you supply, so it may be of any length.
-
notes on fn
example usage:
BC1 = BinaryCounter(0,10)
BC2 = BinaryCounter(10,10)
print(BC1.val()) #[0,0,0,0,0,0,0,0,0,0] left if most significant digit, right is least
print(BC2.val()) #[0,0,0,0,0,0,1,0,1,0]
BC1.increase(1)
BC2.increase(386)
print(BC1.val()) #[0,0,0,0,0,0,0,0,0,1]
print(BC2.val()) #[0,1,1,0,0,0,1,1,0,0]
BC1.BIT_OP(BC2,"OR")
print(BC1.val()) #[0,1,1,0,0,0,1,1,0,1]
print(BC2.val()) #[0,1,1,0,0,0,1,1,0,0]
def randomFn(index,bit,b):#just a random equation that spits out 0,1
return ((bit+b)*(index*b+1))%2
BC3 = BinaryCounter(15,5) #[0,1,1,1,1]
BC1.R_BIT_OP(BC3,randomFn)
print(BC1.val()) #[1,0,0,0,0,0,0,0,1,1]
#to have a smaller array act on a larger:
#use W_BIT_OP and pass in the logical function
#give it the binary (any array of bits)
BC1.W_BIT_OP(BC3, OR) # OR these arrays together, and since BC3 is smaller, loop over until you cover all elements of BC1
#use S_BIT_OP to
BC1.S_BIT_OP(BC3, OR) # OR these arrays together, and since BC3 is smaller, so it returns BC1 partially unmodified
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
BinaryCounters-0.0.3.tar.gz
(8.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file BinaryCounters-0.0.3.tar.gz.
File metadata
- Download URL: BinaryCounters-0.0.3.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47b93473de4193d7dcfb00b76988a1771f34f124aeac30ee021353e265b6b681
|
|
| MD5 |
f6fab692f72badd1e169d284d71c89d3
|
|
| BLAKE2b-256 |
3e38c3ccdad38c42d6e2859fcca7b7f5aa473c46a48366f7fc17cf2c81dfeb34
|
File details
Details for the file BinaryCounters-0.0.3-py3-none-any.whl.
File metadata
- Download URL: BinaryCounters-0.0.3-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0736769671b420d15cefee820570b43e81c3a9f82cea1d2231b490826ddccb4f
|
|
| MD5 |
aff06cfd089572b5f34fecf01b6a9d3c
|
|
| BLAKE2b-256 |
b880471b72fe290c951be7f548b305dfbbd803fbe57fc3da3a18328327f6d0db
|