Bitwise
9 functionsBit operations on an Int, read as a 64-bit two's-complement word. There are
no bit operators: and, or,
xor and not combine words, and the shifts and
rotations move bits. None of them allocates or traps.
Functions
and
Bitwise and. It reads its Int arguments as 64-bit two's-complement
words and answers the word it computes, read the same way.
or
Bitwise or. It reads its Int arguments as 64-bit two's-complement words
and answers the word it computes, read the same way.
xor
Bitwise exclusive or. It reads its Int arguments as 64-bit
two's-complement words and answers the word it computes, read the same way.
not
Every bit flipped: not(n) is -n - 1, so not(0) is -1.
shl
Shift left, filling with zeros. The bits shifted past the top are lost.
The amount, the second argument, is taken modulo 64: shl(n, 64) is n,
shl(n, 65) is shl(n, 1), and a negative amount counts back from 64, so
shl(n, -1) is shl(n, 63). No amount traps.
shr
Arithmetic shift right, filling with copies of the sign bit, so a negative
number stays negative: shr(-8, 1) is -4, and shr(-1, n) is -1. The
amount is taken modulo 64, as shl takes it. No amount traps.
shrU
Logical shift right, filling with zeros, so a negative number turns
positive: shrU(-1, 1) is the largest Int. The amount is taken modulo
64, as shl takes it. No amount traps.
rotl
Rotate left: the bits shifted out of the top come back in at the bottom.
The amount is taken modulo 64, as shl takes it. No amount traps.
rotr
Rotate right: the bits shifted out of the bottom come back in at the top.
The amount is taken modulo 64, as shl takes it. No amount traps.