blops
Bitwise operators, applied to BitArrays.
import gleeunit/should
import blops
// bitwise or
blops.bor(<<0b10101010>>, <<0b10111011>>)
|> should.equal(<<0b10111011>>)
// bitwise and
blops.band(<<0b10101010>>, <<0b10111011>>)
|> should.equal(<<0b10101010>>)
// bitwise xor (not equal)
blops.bneq(<<0b10101010>>, <<0b10111011>>)
|> should.equal(<<0b00010001>>)
// bitwise reverse implication
blops.brevi(<<0b10101010>>, <<0b10111011>>)
|> should.equal(<<0b11101110>>)
Binary Operators
All the binary operators here come in three flavors:
- truncating: The return value is the length of the shorter of the two
operands; they’ll return as soon as they reach the end of one
bit array. These functions have the shortest version of each
set of names (e.g.,
band()for safe bitwise-and). - extending: The return value is the length of the longer of the
two operands; they will behave as if the end of the shorter operand
has been padded with zeros to the length of the longer. These
function names end in an “x” (e.g.,
bandx()for extending bitwise-and). - fallible: These will fail with an error if the lengths of their
operands differ. These function names end with “_try” (e.g.,
band_try()for fallible bitwise-and).
Unary Operator
There is also one unary operator: unary negation, bnot().
Values
pub fn band_try(
a: BitArray,
b: BitArray,
) -> Result(BitArray, errors.LengthMismatch)
pub fn beq_try(
a: BitArray,
b: BitArray,
) -> Result(BitArray, errors.LengthMismatch)
pub fn bimpl_try(
a: BitArray,
b: BitArray,
) -> Result(BitArray, errors.LengthMismatch)
pub fn bnand_try(
a: BitArray,
b: BitArray,
) -> Result(BitArray, errors.LengthMismatch)
pub fn bneq_try(
a: BitArray,
b: BitArray,
) -> Result(BitArray, errors.LengthMismatch)
pub fn bnimpl_try(
a: BitArray,
b: BitArray,
) -> Result(BitArray, errors.LengthMismatch)
pub fn bnor_try(
a: BitArray,
b: BitArray,
) -> Result(BitArray, errors.LengthMismatch)
pub fn bnrevi_try(
a: BitArray,
b: BitArray,
) -> Result(BitArray, errors.LengthMismatch)
pub fn bor_try(
a: BitArray,
b: BitArray,
) -> Result(BitArray, errors.LengthMismatch)
pub fn brevi(a: BitArray, b: BitArray) -> BitArray
bitwise reverse implication (only-if, when)
pub fn brevi_try(
a: BitArray,
b: BitArray,
) -> Result(BitArray, errors.LengthMismatch)