“Bitwise” means it operates on a per-bit basis. Similar to saying “component-wise” to say something is per-component.
(truncated the leading 0s to Int16 for readability)
julia> bitstring(1000)
"0000001111101000"
julia> bitstring(90)
"0000000001011010"
julia> bitstring(1000 & 90)
"0000000001001000"
julia> 1000 & 90
72
julia> bitstring(1000 | 90)
"0000001111111010"
julia> 1000 | 90
1018
For &
, only where both 1000 and 90 have a 1
, the result is 1
. For |
, wherever at least one of them is a 1, the result is 1
.
To add another note here: &
, |
, xor
, and bitshift (<<
/>>
, <<<
/>>>
) are the most fundamental computer operations. All other operations (additions, multiplication, etc.) are built in hardware (and software) using circuits (and code) that perform sequences of these operations. These days you can easily get away with never learning this (I personally didn’t for years) but I think it’s nice to know…
Short-circuit has to do with cutting something off in the middle, or otherwise terminating it before the “end”. Short-circuiting comes from electrical circuits, where if two points in the circuit are connect that shouldn’t be, this creates a short-er circuit than was intended (and often also ruins the device).
julia> false && g()
false
julia> g()
ERROR: UndefVarError: g not defined
Stacktrace:
[1] top-level scope at REPL[65]:1
g()
is not defined, but in the first expression, we never even got to g()
, so we didn’t run in to the error. Encountering false
in a short circuit operation cuts off the evaluation of the expression prematurely. This is why it can be also be used as an if-statement. For example
condition && return _something_
is common.