BitLogic - billbreit/BitWiseApps GitHub Wiki
A set of bit logic tools for implementing "bit logic" or "logic-driven" applications, to be defined as I'm going along.
It is intended for debugging and development of very small and quick but, sometimes, rather high-strung binary logic applications. The idioms and patterns are always a useful reminder of solutions past.
Basic components are:
A wrapper around the int type, only bit-wise logic methods.
- The expression "bitint + int" generates an error.
- The expression "isinstance(BitInt, int)" yields False.
It has an implementation of __iter__ that returns the value of each bit in list form.
- The expression "for b in iter(bitint):" yields a list of 1/0 values.
For instance, int 0b1100 (12) would return the list [ 0, 0, 1, 1 ], reversed from bin format.
- bitlist - determines the collective max bit length for a list of int types.
- bform - provides formats for a given bitlength, always greater or equal to the Python int.bit_length.
- Generalized logical functions, such as "all_of(x, y )", all of x in y.
- Special logical functions such as match and diff. Ex., "match(11, 7)" would return 3, that is "0b1011 & 0b0111" = "0b0011".
See Wikipedia's the section in Boolean Logic discussing subsets as bit vectors.
Wikipedia on:
A massive trove of bit wisdom and algorithmic audacity -> The Algorithms
Peter Hinch has an interesting implementation of bitmap.py
Certainly, debugging and finishing. Maybe get it running on CircuitPython. Add a few more functions. Find and add my implementation of randint for micropython, which blows up with values beyond randint(2^31). I'll find it eventually.