on 6d45ede help sign in
227 lines 3.0 kB history raw
1---
2navhome: /docs
3---
6# 2d: bit logic
7### `++con`
9Binary OR
11Computes the bit-wise logical OR of two [atom]()s, `a` and `b`, producing an
12atom.
14Accepts
15-------
17`a` is an atom
19`b` is an atom
21Produces
22--------
24An atom.
26Source
27------
29 ++ con :: binary or
30 ~/ %con
31 |= {a/@ b/@}
32 =+ [c=0 d=0]
33 |- ^- @
34 ?: ?&(=(0 a) =(0 b)) d
35 %= $
36 a (rsh 0 1 a)
37 b (rsh 0 1 b)
38 c +(c)
39 d %+ add d
40 %^ lsh 0 c
41 ?& =(0 (end 0 1 a))
42 =(0 (end 0 1 b))
43 ==
44 ==
46Examples
47--------
49 > (con 0b0 0b1)
50 1
51 > (con 0 1)
52 1
53 > (con 0 0)
54 0
55 > `@ub`(con 0b1111.0000 0b1.0011)
56 0b1111.0011
57 > (con 4 4)
58 4
59 > (con 10.000 234)
60 10.234
64***
65### `++dis`
67Binary AND
69Computes the bit-wise logical AND of two atoms `a` and `b`, producing an
70atom.
72Accepts
73-------
75`a` is an atom.
77`b` is an atom.
79Produces
80--------
82An atom.
84Source
85------
87 ++ dis :: binary and
88 ~/ %dis
89 |= {a/@ b/@}
90 =| {c/@ d/@}
91 |- ^- @
92 ?: ?|(=(0 a) =(0 b)) d
93 %= $
94 a (rsh 0 1 a)
95 b (rsh 0 1 b)
96 c +(c)
97 d %+ add d
98 %^ lsh 0 c
99 ?| =(0 (end 0 1 a))
100 =(0 (end 0 1 b))
101 ==
102 ==
104Examples
105--------
107 > `@ub`9
108 0b1001
109 > `@ub`5
110 0b101
111 > `@ub`(dis 9 5)
112 0b1
113 > (dis 9 5)
114 1
115 > `@ub`534
116 0b10.0001.0110
117 > `@ub`987
118 0b11.1101.1011
119 > `@ub`(dis 534 987)
120 0b10.0001.0010
121 > (dis 534 987)
122 530
126***
127### `++mix`
129Binary XOR
131Produces the bit-wise logical XOR of `a` and `b`, producing an atom.
133Accepts
134-------
136`a` is an atom
138`b` is an atom
140Produces
141--------
143An atom.
145Source
146------
148 ++ mix :: binary xor
149 ~/ %mix
150 |= {a/@ b/@}
151 ^- @
152 =+ [c=0 d=0]
153 |-
154 ?: ?&(=(0 a) =(0 b)) d
155 %= $
156 a (rsh 0 1 a)
157 b (rsh 0 1 b)
158 c +(c)
159 d (add d (lsh 0 c =((end 0 1 a) (end 0 1 b))))
160 ==
162Examples
163--------
165 > `@ub`2
166 0b10
167 > `@ub`3
168 0b11
169 > `@ub`(mix 2 3)
170 0b1
171 > (mix 2 3)
172 1
173 > `@ub`(mix 2 2)
174 0b0
175 > (mix 2 2)
176 0
180***
181### `++not`
183Binary NOT
185Computes the bit-wise logical NOT of the bottom `b` blocks of size `a`
186of `c`.
188Accepts
189-------
191`a` is a block size (see `++bloq`).
193`b` is an atom.
195`c` is an atom.
197Produces
198--------
200An atom.
202Source
203------
205 ++ not |= {a/bloq b/@ c/@} :: binary not (sized)
206 (mix c (dec (bex (mul b (bex a)))))
209Examples
210--------
212 > `@ub`24
213 0b1.1000
214 > (not 0 5 24)
215 7
216 > `@ub`7
217 0b111
218 > (not 2 5 24)
219 1.048.551
220 > (not 2 5 1.048.551)
221 24
222 > (not 1 1 (not 1 1 10))
223 10
227***