Bitwise
Core
Library for bitwise operations.
Values are treated as 32-bit signed integers, matching JavaScript Bitwise so dual-target code stays consistent.
Basic Operations
@docs and, or, xor, complement
Bit Shifts
@docs shiftLeftBy, shiftRightBy, shiftRightZfBy
Values
and
and : Int -> Int -> IntBitwise AND
Examples
and 5 3 == 1
and 7 1 == 1or
or : Int -> Int -> IntBitwise OR
Examples
or 5 3 == 7
or 4 1 == 5xor
xor : Int -> Int -> IntBitwise XOR
Examples
xor 5 3 == 6
xor 7 1 == 6complement
complement : Int -> IntFlip each bit individually, often called bitwise NOT
Examples
complement 0 == -1
complement -1 == 0shiftLeftBy
shiftLeftBy : Int -> Int -> IntShift bits to the left by a given offset, filling new bits with zeros. This can be used to multiply numbers by powers of two.
Examples
shiftLeftBy 1 5 == 10
shiftLeftBy 5 1 == 32shiftRightBy
shiftRightBy : Int -> Int -> IntShift bits to the right by a given offset, filling new bits with whatever is the topmost bit. This can be used to divide numbers by powers of two.
Examples
shiftRightBy 1 32 == 16
shiftRightBy 2 32 == 8
shiftRightBy 1 -32 == -16This is called an arithmetic right shift, often written >>, and sometimes called a sign-propagating right shift because it fills empty spots with copies of the highest bit.
shiftRightZfBy
shiftRightZfBy : Int -> Int -> IntShift bits to the right by a given offset, filling new bits with zeros.
Examples
shiftRightZfBy 1 32 == 16
shiftRightZfBy 2 32 == 8
shiftRightZfBy 1 -32 == 2147483632This is called a logical right shift, often written >>>, and sometimes called a zero-fill right shift because it fills empty spots with zeros.