Bitwise Functions

$bitwiseNot()

Signature: $bitwiseNot(int)

Performs a bitwise NOT operation on a number. This inverts each bit of the input: 0 becomes 1, and 1 becomes 0.

Parameters

Parameter Type Description
int int The number to invert (Required)

Examples

$bitwiseNot(2) => -3 // because 2 (000...0010) becomes -3 (111...1101 in two's complement)

$bitwiseAnd()

Signature: $bitwiseAnd(int, int)

Performs a bitwise AND operation between two numbers. Each bit in the result is set to 1 only if the corresponding bits in both input numbers are 1.

Parameters

Parameter Type Description
int int First number (Required)
int int Second number (Required)

Examples

$bitwiseAnd(6, 3) => 2 // because 6 (110) & 3 (011) = 2 (010)

$bitwiseOr()

Signature: $bitwiseOr(int, int)

Performs a bitwise OR operation between two numbers. Each bit in the result is set to 1 if at least one of the corresponding bits in the input numbers is 1.

Parameters

Parameter Type Description
int int First number (Required)
int int Second number (Required)

Examples

$bitwiseOr(6, 3) => 7 // because 6 (110) | 3 (011) = 7 (111).

$bitwiseXor()

Signature: $bitwiseXor(int, int)

Performs a bitwise XOR (exclusive OR) operation between two numbers. Each bit in the result is set to 1 only if the corresponding bits in the input numbers are different.

Parameters

Parameter Type Description
int int First number (Required)
int int Second number (Required)

Examples

$bitwiseXor(6, 3) => 5 // because 6 (110) ^ 3 (011) = 5 (101).

$bitwiseShiftLeft()

Signature: $bitwiseShiftLeft(int, int)

Shifts the bits of the first number to the left by the number of positions specified by the second argument. Each left shift multiplies the number by 2 for each position.

Parameters

Parameter Type Description
int int Number to shift (Required)
int int Number of positions (Required)

Examples

$bitwiseShiftLeft(3, 2) => 12 // because 3 (11) shifted left by 2 becomes 12 (1100).

$bitwiseShiftRight()

Signature: $bitwiseShiftRight(int, int)

Shifts the bits of the first number to the right by the number of positions specified by the second argument. Each right shift divides the number by 2 for each position, discarding bits shifted off.

Parameters

Parameter Type Description
int int Number to shift (Required)
int int Number of positions (Required)

Examples

$bitwiseShiftRight(8, 2) => 2 // because 8 (1000) shifted right by 2 becomes 2 (10).