blops
blops supplies functions for applying
bitwise operators
to bit arrays.
Operators
There are sixteen possible bitwise binary operators. Six of them are trivial and are not included here:
false: always returnsFalsefirst: always returns the value of the first operand; it is equivalent to just using the first argument in place of the return valuesecond: always returns the value of the second operand; it is equivalent to just using the second argument in place of the return value!false: (that is,true) always returnsTrue!first: equivalent tobnot(first_arg)!second: equivalent tobnot(second_arg)
The following table describes the ten operations that are included:
p -> 0 0 1 1
Op q -> 0 1 0 1 Also known as
and 0 0 0 1
!imply 0 0 1 0 not-if-then
!rev imply 0 1 0 0 not-only-if, not-because
!or 1 0 0 0 nor, none, neither
!equal 0 1 1 0 xor
equal 1 0 0 1
or 0 1 1 1
rev imply 1 0 1 1 only-if, because
imply 1 1 0 1 if-then
!and 1 1 1 0 nand, not all
There is also the unary bitwise negation operator.
Integers
As a convenience, there is also a module for performing these operations on integers of various sizes and signedness.
Performance
This is a pure Gleam package. Obviously, this would be faster if we had access to mutable, indexable arrays.