Convert a hex string to list of binary numbers.
>>> fromHex "8" |> toIntegers
[ 1, 0, 0, 0 ]Convert a list of binary numbers to a hex string.
>>> toHex <| fromIntegers [ 1, 0, 0, 0 ]
"8"Convert a decimal to Bits.
>>> fromDecimal 8 |> toIntegers
[ 1, 0, 0, 0 ]Convert a list of integers to Bits.
Everything below zero and zero itself becomes a 0 bit,
and everything above zero becomes a 1 bit.
>>> fromIntegers [ 1, 0, 0, 0 ] |> toHex
"8"Convert Bits to a list of integers.
>>> toIntegers <| fromHex "8"
[ 1, 0, 0, 0 ]Convert a list of booleans to Bits.
>>> fromBooleans [ True, False, False, False ] |> toHex
"8"Convert Bits to a list of booleans.
>>> toBooleans <| fromHex "8"
[ True, False, False, False ]AND operator.
-- 0101 (decimal 5)
-- AND 0011 (decimal 3)
-- = 0001 (decimal 1)
>>> Binary.and
..> (fromHex "5")
..> (fromHex "3")
ensureBits 3 (fromHex "1")OR operator.
-- 0101 (decimal 5)
-- OR 0011 (decimal 3)
-- = 0111 (decimal 7)
>>> Binary.or
..> (fromHex "5")
..> (fromHex "3")
fromHex "7"XOR operator.
-- 0101 (decimal 5)
-- XOR 0011 (decimal 3)
-- = 0110 (decimal 6)
>>> Binary.xor
..> (fromHex "5")
..> (fromHex "3")
fromHex "6"NOT operator.
-- NOT 0111 (decimal 7)
-- = 1000 (decimal 8)
>>> Binary.not
..> (fromIntegers [ 0, 1, 1, 1 ])
fromIntegers [ 1, 0, 0, 0 ]Arithmetic/Logical left shift.
-- LEFTSHIFT 00010111 (decimal 23)
-- = 00101110 (decimal 46)
>>> [ 0, 0, 0, 1, 0, 1, 1, 1 ]
..> |> fromIntegers
..> |> shiftLeftBy 1
..> |> toIntegers
[ 0, 0, 1, 0, 1, 1, 1, 0 ]Arithmetic right shift.
-- ARI-RIGHTSHIFT 10010111 (decimal 151)
-- = 11001011 (decimal 203)
>>> [ 1, 0, 0, 1, 0, 1, 1, 1 ]
..> |> fromIntegers
..> |> shiftRightBy 1
..> |> toIntegers
[ 1, 1, 0, 0, 1, 0, 1, 1 ]Logical right shift.
-- LOG-RIGHTSHIFT 10010111 (decimal 151)
-- = 00001011 (decimal 11)
>>> [ 0, 0, 0, 1, 0, 1, 1, 1 ]
..> |> fromIntegers
..> |> shiftRightZfBy 1
..> |> toIntegers
[ 0, 0, 0, 0, 1, 0, 1, 1 ]Rotate a binary sequence to the left.
NOTE: Make sure your binary sequence is of the correct size before rotating! Rotating 8 bits is not always the same as, for example, 16 bits.
>>> rotateLeftBy 1 (ensureBits 32 <| fromHex "17")
ensureBits 32 (fromHex "2E")
>>> rotateLeftBy 2 (ensureBits 32 <| fromHex "96")
ensureBits 32 (fromHex "258")Rotate a binary sequence to the right.
NOTE: Make sure your binary sequence is of the correct size before rotating! Rotating 8 bits is not always the same as, for example, 16 bits.
>>> rotateRightBy 1 (ensureBits 64 <| fromHex "17")
ensureBits 64 (fromHex "800000000000000B")
>>> rotateRightBy 1 (ensureBits 32 <| fromHex "96")
ensureBits 32 (fromHex "4B")
>>> rotateRightBy 5 (ensureBits 32 <| fromHex "96")
ensureBits 32 (fromHex "B0000004")Add two sets of bits together.
-- ADD 1011
-- 1011
-- = 10110
>>> add
..> (fromIntegers [ 1, 0, 1, 1 ])
..> (fromIntegers [ 1, 0, 1, 1 ])
fromIntegers [ 1, 0, 1, 1, 0 ]
>>> add
..> (fromIntegers [ 1, 1, 1, 0, 1 ])
..> (fromIntegers [ 1, 0, 1, 0 ])
fromIntegers [ 1, 0, 0, 1, 1, 1 ]Subtract two sets of bits from each other.
-- SUBTRACT 1011
-- 11
-- = 1010
>>> subtract
..> (fromIntegers [ 1, 0, 1, 1 ])
..> (fromIntegers [ 1, 1 ])
fromIntegers [ 1, 0, 0, 0 ]
>>> subtract
..> (fromIntegers [ 1, 0, 0, 0, 1 ])
..> (fromIntegers [ 0, 0, 1, 0, 0 ])
fromIntegers [ 0, 1, 1, 0, 1 ]Ensure the binary sequence length is of certain size.
>>> ensureBits 4 (fromIntegers [ 1, 0 ])
fromIntegers [ 0, 0, 1, 0 ]Drops the leading zeros of a binary sequence.
>>> dropLeadingZeros (fromIntegers [ 0, 0, 1, 0 ])
fromIntegers [ 1, 0 ]Makes two sequences isometric (equal in size).
>>> makeIsometric
..> (fromIntegers [ 0, 1, 0 ])
..> (fromIntegers [ 1, 0, 0, 0 ])
( fromIntegers [ 0, 0, 1, 0 ]
, fromIntegers [ 1, 0, 0, 0 ]
)
The binary sequence.
Use convertors to make
Bits.