Atom

Arithmetic and bitwise operations

Use a mask to keep selected bits

Bitwise AND is useful when different parts of an integer store different information.

Atom
print(0x2f & 0x0f)
Output
15

The mask keeps the lowest four bits. For ordinary arithmetic use the numeric operators.

Integer addition, subtraction and multiplication check overflow. Arithmetic with an unsigned integer and a negative signed integer raises an error unless the operation promotes to floating point. Division and exponentiation return binary64. Remainder is division toward zero for integers and uses the C floating remainder for floating-point operands. Division and remainder by zero raise errors. Bitwise operations work on 64-bit integers. Shifts accept counts from 0 through 63, with arithmetic right shift for signed values.