@@ -3,38 +3,54 @@ module Bits where
4{-| Library for [bitwise operations](http://en.wikipedia.org/wiki/Bitwise_operation).
4{-| Library for [bitwise operations](http://en.wikipedia.org/wiki/Bitwise_operation).
8+@docs and, or, xor, complement
6−@docs and, or, xor, complement, shiftLeft, shiftRight, shiftRightLogical
12+@docs shiftLeft, shiftRight, shiftRightLogical
9import Native.Bits
15import Native.Bits
11−{-| Performs the AND operation on each pair of bits.
17+{-| Bitwise “and”
13and : Int -> Int -> Int
19and : Int -> Int -> Int
14and = Native.Bits.and
20and = Native.Bits.and
16−{-| Performs the OR operation on each pair of bits.
22+{-| Bitwise “or”
18or : Int -> Int -> Int
24or : Int -> Int -> Int
19or = Native.Bits.or
25or = Native.Bits.or
21−{-| Performs the XOR operation on each pair of bits.
27+{-| Bitwise “xor”
23xor : Int -> Int -> Int
29xor : Int -> Int -> Int
24xor = Native.Bits.xor
30xor = Native.Bits.xor
26−{-| Performs the NOT operation on each bit.
32+{-| Flip each bit individually, often called “bitwise not”
28complement : Int -> Int
34complement : Int -> Int
29complement = Native.Bits.complement
35complement = Native.Bits.complement
31{-| Shift bits to the left by a given offset, filling new bits with zeros.
37{-| Shift bits to the left by a given offset, filling new bits with zeros.
38+This can be used to multiply numbers by powers of two.
40+ 8 `shiftLeft` 1 == 16
41+ 8 `shiftLeft` 2 == 32
33shiftLeft : Int -> Int -> Int
43shiftLeft : Int -> Int -> Int
34shiftLeft = Native.Bits.shiftLeft
44shiftLeft = Native.Bits.shiftLeft
36{-| Shift bits to the right by a given offset, filling new bits with
46{-| Shift bits to the right by a given offset, filling new bits with
47+whatever is the topmost bit. This can be used to divide numbers by powers of two.
49+ 32 `shiftRight` 1 == 16
50+ 32 `shiftRight` 2 == 8
51+ -32 `shiftRight` 1 == -16
37−whatever is the topmost bit. This is an [arithmatic right
53+This is called an [arithmatic right
38shift](http://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift),
54shift](http://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift),
39often written (>>), and sometimes called a “sign-propagating”
55often written (>>), and sometimes called a “sign-propagating”
40right shift because it fills empty spots with copies of the highest bit.
56right shift because it fills empty spots with copies of the highest bit.
@@ -43,7 +59,13 @@ shiftRight : Int -> Int -> Int
43shiftRight = Native.Bits.shiftRightArithmatic
59shiftRight = Native.Bits.shiftRightArithmatic
45{-| Shift bits to the right by a given offset, filling new bits with
61{-| Shift bits to the right by a given offset, filling new bits with
64+ 32 `shiftRightLogical` 1 == 16
65+ 32 `shiftRightLogical` 2 == 8
66+ -32 `shiftRightLogical` 1 == 2147483632
46−zeros. This is an [logical right
68+This is called an [logical right
47shift](http://en.wikipedia.org/wiki/Bitwise_operation#Logical_shift), often written (>>>),
69shift](http://en.wikipedia.org/wiki/Bitwise_operation#Logical_shift), often written (>>>),
48and sometimes called a “zero-fill” right shift because it fills empty spots
70and sometimes called a “zero-fill” right shift because it fills empty spots
49with zeros.
71with zeros.