Operators

Bitwise operators — +& +| +^ +< +>

Full

Integer bit manipulation — and, or, xor, and shifts, all with a + prefix.

Raku's bitwise operators work on the binary representation of integers. They all carry a + prefix to mark them as the numeric (bit) versions — +&, +|, +^ for and/or/xor, and +<, +> for left and right shifts. (The ?-prefixed forms ?&, ?|, ?^ are the boolean versions, and ~&/~|/~^ are the string ones.)

and, or, xor #

Each operator combines the bits of its two operands.

say 0b1100 +& 0b1010;
say 0b1100 +| 0b1010;
say 0b1100 +^ 0b1010;
Output
8
14
6

Reading the bits: 1100 +& 1010 keeps only bits set in both1000 (8); +| keeps bits set in either1110 (14); +^ keeps bits set in exactly one → 0110 (6). The 0b… literals are just a readable way to write the same integers (see Integer literals).

Shifting #

+< shifts the bits left (multiply by a power of two); +> shifts right (integer divide).

say 1 +< 8;
say 256 +> 2;
Output
256
64

1 +< 8 moves the single bit eight places left — 2⁸ = 256; 256 +> 2 drops two low bits — 256 / 4 = 64.

Notes #