Skip to main content

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)

  • val is the starting value of the binary,

  • bitLength is the size of the array holding the binary.

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):

  • fromSig if true, sorts all 1's to the most significant digit
  • sorts the binary

SECTION(<int>=start,<int>=stop):

  • returns a new array of that section of binary

SPAWN(<int>=start,<int>=stop):

  • returns a new <BinaryCounter> from that section of binary

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):

  • logically shifts binary << up

SHIFT_DOWN( <int>=amount):

  • logically shifts binary >> down

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):

  • if countOnes: count 1's in binary, else count 0's

READ():

  • prints a status in the console

SIZE():

  • returns the length of the binary array

GET_MAX():

  • returns the maximum int value based on size of array.

SET_BIT_LENGTH(<int>=len):

  • len sets the length of the array holding the bits.

B_TO_I(<int>[]=bin):

  • bin is an array of binary numbers (or any numbers), such as <BinaryCounter>.binary
  • returns an int

VAL():

  • returns value of binary

BIN():

  • returns array that represents binary

SET_V(<int>=value):

  • sets value of binary

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)

  • val is 1/0,
  • pos is goes from least significant digit to most
  • pos is 0 based

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
    • it is a function you supply
    • it must return 0 or 1
    • it's inputs are: (<int>=pos, <int>=bit1, <int>=bit2)
      • pos begins at the least significant digit and move to the most significant digit in the array.
      • bit1 is the method owner's bit
      • bit2 is the comparison bit. derived from pos % the length of the comparison array

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    

Release files for BinaryCounters 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for BinaryCounters 0.0.3
File Size Uploaded
BinaryCounters-0.0.3.tar.gz 8.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for BinaryCounters 0.0.3
File Interpreter ABI Platform
BinaryCounters-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / BinaryCounters-0.0.3.tar.gz

Download URL BinaryCounters-0.0.3.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
47b93473de4193d7dcfb00b76988a1771f34f124aeac30ee021353e265b6b681
BLAKE2b-256 checksum
How to use checksums
3e38c3ccdad38c42d6e2859fcca7b7f5aa473c46a48366f7fc17cf2c81dfeb34
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / BinaryCounters-0.0.3-py3-none-any.whl

Download URL BinaryCounters-0.0.3-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0736769671b420d15cefee820570b43e81c3a9f82cea1d2231b490826ddccb4f
BLAKE2b-256 checksum
How to use checksums
b880471b72fe290c951be7f548b305dfbbd803fbe57fc3da3a18328327f6d0db
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page