1# Bit
2bitwise library
3
4# functions
5### logand
6logand returns the bitwise AND of the two arguments.
7
8```
9> (logand #b0101 #b0011)
101
11```
12
13### logior
14logior returns the bitwise OR for the two arguments.
15
16```
17> (logior #b0101 #b0011)
187
19```
20
21### logxor
22logxor returns the bit-by-bit exclusive OR for the two arguments.
23
24
25```
26> (logxor #b0101 #b0011)
276
28```
29
30### lognot
31lognot returns a bit-by-bit logical negation of the argument.
32
33```
34> (lognot 0)
35-1  ; #b1111 .... 1111
36
37> (logand 0 -1)
380
39> (lognot 1)
40-2  ; #b1111 .... 1110
41
42> (logand 1 -2)
430
44```
45
46### logtest
47logtest returns NIL if the result of logand is 0, T otherwise.
48
49```
50> (logtest 3 1)
51T
52
53> (logand 3 1)
541
55
56> (logtest 3 4)
57NIL
58
59> (logand 3 4)
600
61
62```
63
64### logbitp
65logbitp returns T if the bit of the integer at the position of the subscript index is 1.
66Conversely, if it is 0, NIL is returned. Bit positions are counted from 0, as in arrays.
67
68```
69> (logbitp 0 #b0101)
70T
71
72> (logbitp 1 #b0101)
73NIL
74```
75
76### logcount
77logcount counts and returns 1 bit if integer is a positive value.
78If it is a negative value, it counts and returns 0 bits.
79
80```
81> (logcount 13)
823   ; #b...0001101
83
84> (logcount -13)
852   ; #b...1110011
86```
87
88### ash
89ash shifts integer to the left by count bits.
90The low-order bit is inserted with 0. If count is negative, it shifts count bits to the right.
91
92```
93> (ash 1 8)
94256
95> (ash -1 8)
96-256
97> (ash 256 -8)
981
99```