hw-bits-0.7.1.5: Bit manipulation

Safe HaskellNone
LanguageHaskell2010

HaskellWorks.Data.Bits.Broadword.Word8

Synopsis

Documentation

h :: Int -> Word8 Source #

Initialise all sub-words of size k where k ∈ { 2, 4, 8, 16, 32 } such that the highest bit is set to 1 and all other bits are cleared.

>>> import Numeric(showHex)
>>> showHex (h 2) ""
"aa"
>>> showHex (h 4) ""
"88"
>>> showHex (h 8) ""
"80"

l :: Int -> Word8 Source #

Initialise all sub-words of size k where k ∈ { 2, 4, 8, 16, 32 } such that the lowest bit is set to 1 and all other bits are cleared.

>>> import Numeric(showHex)
>>> showHex (l 2) ""
"55"
>>> showHex (l 4) ""
"11"
>>> showHex (l 8) ""
"1"

kBitDiff :: Int -> Word8 -> Word8 -> Word8 Source #

Broadword subtraction of sub-words of size k where k ∈ { 2, 4, 8 }.

The subtraction respects 2's complement so sub-words may be regarded as signed or unsigned words.

>>> import Numeric(showHex)
>>> showHex (kBitDiff 8 0x02 0x01) ""
"1"
>>> showHex (kBitDiff 8 0x01 0x02) ""
"ff"
>>> showHex (kBitDiff 8 0xff 0xff) ""
"0"

kBitDiffPos :: Int -> Word8 -> Word8 -> Word8 Source #

Broadword subtraction of sub-words of size k where k ∈ { 2, 4, 8 } where results are bounded from below by 0.

>>> import Numeric(showHex)
>>> showHex (kBitDiff 8 0x02 0x01) ""
"1"
>>> showHex (kBitDiff 8 0x01 0x02) ""
"ff"
>>> showHex (kBitDiff 8 0xff 0xff) ""
"0"

kBitDiffUnsafe :: Int -> Word8 -> Word8 -> Word8 Source #

Broadword subtraction of sub-words of size k where k ∈ { 2, 4, 8 } where all the sub-words of x and y must not have the signed bit set for the result to be meaningful.

>>> import Numeric(showHex)
>>> showHex (kBitDiffUnsafe 8 0x02 0x01) ""
"1"
>>> showHex (kBitDiffUnsafe 8 0x01 0x02) ""
"ff"
>>> showHex (kBitDiffUnsafe 8 0xff 0xff) "" -- produces nonsense in the last sub-word
"80"