hw-bits-0.7.2.1: Bit manipulation

Safe HaskellNone
LanguageHaskell2010

HaskellWorks.Data.Bits.Broadword.Word16

Synopsis

Documentation

h :: Int -> Word16 Source #

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

>>> import Numeric(showHex)
>>> showHex (h 2) ""
"aaaa"
>>> showHex (h 4) ""
"8888"
>>> showHex (h 8) ""
"8080"
>>> showHex (h 16) ""
"8000"

l :: Int -> Word16 Source #

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

>>> import Numeric(showHex)
>>> showHex (l 2) ""
"5555"
>>> showHex (l 4) ""
"1111"
>>> showHex (l 8) ""
"101"
>>> showHex (l 16) ""
"1"

kBitDiff :: Int -> Word16 -> Word16 -> Word16 Source #

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

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

>>> import Numeric(showHex)
>>> showHex (kBitDiff 8 0x0201 0x0101) ""
"100"
>>> showHex (kBitDiff 8 0x0201 0x0102) ""
"1ff"
>>> showHex (kBitDiff 8 0x20ff 0x10ff) ""
"1000"

kBitDiffPos :: Int -> Word16 -> Word16 -> Word16 Source #

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

>>> import Numeric(showHex)
>>> showHex (kBitDiffPos 8 0x0201 0x0101) ""
"100"
>>> showHex (kBitDiffPos 8 0x0201 0x0102) ""
"100"
>>> showHex (kBitDiffPos 8 0x20ff 0x10ff) ""
"1000"

kBitDiffUnsafe :: Int -> Word16 -> Word16 -> Word16 Source #

Broadword subtraction of sub-words of size k where k ∈ { 2, 4, 8, 16, 32, 64 } 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 0x0201 0x0101) ""
"100"
>>> showHex (kBitDiffUnsafe 8 0x0201 0x0102) ""
"1ff"
>>> showHex (kBitDiffUnsafe 8 0x20ff 0x10ff) "" -- produces nonsense in the last sub-word
"1080"