liveBook · Manning

Bit-or

As explained in Clojure: The Essential Reference

bit-or is a Clojure function that applies bitwise disjunction to two or more integer arguments.

bit-or is a Clojure function that combines the corresponding bits of two or more integer arguments using bitwise disjunction. It accepts byte, short, int, or long values and returns a java.lang.Long. section 3.2.3

Listing 3.9. → bitwise, bit-processing
(bit-not [x])

(bit-and [x y & more])
(bit-or [x y & more])
(bit-xor [x y & more])
(bit-and-not [x y & more])

(bit-clear [x n])
(bit-set [x n])
(bit-flip [x n])
(bit-test [x n])
(bit-shift-left [x n])
(bit-shift-right [x n])
(unsigned-bit-shift-right [x n])

The signature shows that bit-or requires at least two arguments and accepts any number of additional operands. section 3.2.3

Combining bit patterns

bit-or can be compared with bit-xor over the same inputs: (map bin ((juxt bit-or bit-xor) 2r1 2r1)) returns ("00000001" "00000000"). Identical set bits remain set under OR but cancel under XOR. section 3.2.3

How Clojure: The Essential Reference covers it

How deep it goes
Defines accepted numeric types, variadic arity, return type, and invalid-input exceptions, with one binary comparison.
Examples
Uses binary literals, bin, juxt, and a bit-or versus bit-xor comparison.
What it assumes
Assumes familiarity with integer values and binary bit patterns while establishing the function’s arity and type contract.
What you can do after
Apply it via Clojure to combine two or more integer bit patterns and inspect the resulting binary value.
How it connects
Connects bit-or with bit-and, bit-xor, bit masks, and binary representations.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.