on 140ac0e help sign in
222 lines 2.9 kB history raw
1# 2d: bit logic
2### `++con`
4Binary OR
6Computes the bit-wise logical OR of two [atom]()s, `a` and `b`, producing an
7atom.
9Accepts
10-------
12`a` is an atom
14`b` is an atom
16Produces
17--------
19An atom.
21Source
22------
24 ++ con :: binary or
25 ~/ %con
26 |= {a/@ b/@}
27 =+ [c=0 d=0]
28 |- ^- @
29 ?: ?&(=(0 a) =(0 b)) d
30 %= $
31 a (rsh 0 1 a)
32 b (rsh 0 1 b)
33 c +(c)
34 d %+ add d
35 %^ lsh 0 c
36 ?& =(0 (end 0 1 a))
37 =(0 (end 0 1 b))
38 ==
39 ==
41Examples
42--------
44 > (con 0b0 0b1)
45 1
46 > (con 0 1)
47 1
48 > (con 0 0)
49 0
50 > `@ub`(con 0b1111.0000 0b1.0011)
51 0b1111.0011
52 > (con 4 4)
53 4
54 > (con 10.000 234)
55 10.234
59***
60### `++dis`
62Binary AND
64Computes the bit-wise logical AND of two atoms `a` and `b`, producing an
65atom.
67Accepts
68-------
70`a` is an atom.
72`b` is an atom.
74Produces
75--------
77An atom.
79Source
80------
82 ++ dis :: binary and
83 ~/ %dis
84 |= {a/@ b/@}
85 =| {c/@ d/@}
86 |- ^- @
87 ?: ?|(=(0 a) =(0 b)) d
88 %= $
89 a (rsh 0 1 a)
90 b (rsh 0 1 b)
91 c +(c)
92 d %+ add d
93 %^ lsh 0 c
94 ?| =(0 (end 0 1 a))
95 =(0 (end 0 1 b))
96 ==
97 ==
99Examples
100--------
102 > `@ub`9
103 0b1001
104 > `@ub`5
105 0b101
106 > `@ub`(dis 9 5)
107 0b1
108 > (dis 9 5)
109 1
110 > `@ub`534
111 0b10.0001.0110
112 > `@ub`987
113 0b11.1101.1011
114 > `@ub`(dis 534 987)
115 0b10.0001.0010
116 > (dis 534 987)
117 530
121***
122### `++mix`
124Binary XOR
126Produces the bit-wise logical XOR of `a` and `b`, producing an atom.
128Accepts
129-------
131`a` is an atom
133`b` is an atom
135Produces
136--------
138An atom.
140Source
141------
143 ++ mix :: binary xor
144 ~/ %mix
145 |= {a/@ b/@}
146 ^- @
147 =+ [c=0 d=0]
148 |-
149 ?: ?&(=(0 a) =(0 b)) d
150 %= $
151 a (rsh 0 1 a)
152 b (rsh 0 1 b)
153 c +(c)
154 d (add d (lsh 0 c =((end 0 1 a) (end 0 1 b))))
155 ==
157Examples
158--------
160 > `@ub`2
161 0b10
162 > `@ub`3
163 0b11
164 > `@ub`(mix 2 3)
165 0b1
166 > (mix 2 3)
167 1
168 > `@ub`(mix 2 2)
169 0b0
170 > (mix 2 2)
171 0
175***
176### `++not`
178Binary NOT
180Computes the bit-wise logical NOT of the bottom `b` blocks of size `a`
181of `c`.
183Accepts
184-------
186`a` is a block size (see `++bloq`).
188`b` is an atom.
190`c` is an atom.
192Produces
193--------
195An atom.
197Source
198------
200 ++ not |= {a/bloq b/@ c/@} :: binary not (sized)
201 (mix c (dec (bex (mul b (bex a)))))
204Examples
205--------
207 > `@ub`24
208 0b1.1000
209 > (not 0 5 24)
210 7
211 > `@ub`7
212 0b111
213 > (not 2 5 24)
214 1.048.551
215 > (not 2 5 1.048.551)
216 24
217 > (not 1 1 (not 1 1 10))
218 10
222***