11Computes the bitwise logical OR of two atoms, `a` and `b`, producing an atom.
31 ?: ?&(=(0 a) =(0 b)) d
56 > `@ub`(con 0b1111.0000 0b1.0011)
80`con` performs the bitwise operation OR, a concept that's general to computing.
81It compares each bit of its first sample to the corresponding bit of its second
82sample. If either bit is 1, the corresponding product bit is set
83to 1. Otherwise, the corresponding product bit is set to 0.
85Take the example of `(con 8 12)`. It's easy to see how this operation works when
86its samples and its product are stacked.
91 0b1100 :: 12 (product)
94Note that the names `con` (conjunction) for OR and `dis` (disjunction) for AND
95are given to opposite operators in Hoon when compared to other computing
96contexts. That's because `0` is true in Hoon and `1` is false. Outside of Hoon,
97where `0` is false and `1` is true, bitwise OR is the logical disjunction and
98bitwise AND is the logical conjunction.
106Computes the bitwise logical AND of two atoms, `a` and `b`, producing an atom.
126 ?: ?|(=(0 a) =(0 b)) d
169`dis` performs the bitwise AND, an operation general to computing. It compares
170each bit of its first sample to the corresponding bit of its second sample. If
171both bits are 1, the corresponding product bit is set to 1. Otherwise, the
172corresponding product bit is set to 0.
174Take the example of `(dis 8 12)`. It's easy to see how this operation works when
175its samples and its product are stacked.
179 0b1100 :: 12 (sample)
180 0b1000 :: 8 (product)
183Note that the names `dis` (disjunction) for AND and `con` (conjuction) for OR
184are given to opposite operators in Hoon when compared to other computing
185contexts. That's because `0` is true in Hoon and `1` is false. Outside of Hoon,
186where `0` is false and `1` is true, bitwise OR is the logical disjunction and
187bitwise AND is the logical conjunction.
194Produces the bitwise logical XOR of two atoms, `a` and `b`, producing an atom.
215 ?: ?&(=(0 a) =(0 b)) d
220 d (add d (lsh 0 c =((end 0 1 a) (end 0 1 b))))
260`mix` performs the bitwise XOR (exclusive-OR), an operation that's general to
261computing. compares each bit of its first sample to the corresponding bit of its
262second sample. If one bit is 0 and the other bit is 1, the corresponding product
263bit is set to 1. Otherwise, the corresponding product bit is set to 0.
265Take the example of `(mix 8 12)`. It's easy to see how this operation works when
266its samples and its product are stacked.
270 0b1100 :: 12 (sample)
279Computes the bitwise logical NOT of the bottom `b` blocks of size `a`
284`a` is a block size (see [`bloq`](@/docs/hoon/reference/stdlib/1c.md)).
297 ++ not |= [a=bloq b=@ c=@]
298 (mix c (dec (bex (mul b (bex a)))))
316 > (not 2 5 1.048.551)
319 > (not 1 1 (not 1 1 10))
325In computing in general, the bitwise operation NOT simply turns a binary
326number's `0`s into `1`s, and vice versa.
328In Hoon, we ask for a little more information to use `not`, because binary
329numbers have a number of implicit leading zeroes differently depending on on
330their [block size](@/docs/hoon/reference/stdlib/1c.md). Decimal `7`, for example, is `0b111` in binary, and
331has one implicit zero in the context of a block of size `2`, which has a
332bitwidth of 4. Let's try `not` on `7` with a single block of size `2`.
335 > `@ub`(not 2 1 0b111)
342This happened because `0b111` is considered as `0b0111` by the `not` operator
343when dealing with a single block of size `2`. The NOT of `7`, then, is `0b1000`,
346When we pass `not` a single block of size `3`, there is a bitwidth of 8 to
347fill with binary information. So the remaining leading digits of `0b111` are,
348again, treated as `0`.
351 > `@ub`(not 3 1 0b111)
358This works when going to a smaller block size, too.
361 > `@ub`(not 1 1 0b1011)
368What's happening here may not be readily apparent. But we're only flipping the
369last block of size `1` (bitwidth 2) of the binary `0b111`. That is, we leave
370the "0b1" piece just the same and manipulate the "11" that the number ends with.
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list