Current section
Files
Jump to
Current section
Files
README.md
# blops
[](https://hex.pm/packages/blops)
[](https://blops.hexdocs.pm/)
`blops` supplies functions for applying
[bitwise operators](https://en.wikipedia.org/wiki/Bitwise_operation)
to bit arrays.
## Operators
There are sixteen possible [bitwise binary
operators](https://en.wikipedia.org/wiki/Bitwise_operation#Truth_table_for_all_binary_logical_operators).
Six of them are trivial and are not included here:
* `false`: always returns `False`
* `first`: always returns the value of the first operand; it is equivalent
to just using the first argument in place of the return value
* `second`: 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 returns `True`
* `!first`: equivalent to `bnot(first_arg)`
* `!second`: equivalent to `bnot(second_arg)`
The following table describes the ten operations that are included:
```text
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.