Skip to main content

Bitwise Functions

AMPS provides a set of functions for performing bitwise operations on integers.

BITWISE_GET_BIT

BITWISE_GET_BIT


BITWISE_GET_BIT(N, Position)

Returns the value of a specific bit in an integer.

Parameters

  • N: The integer to examine.
  • Position: The position of the bit to get. The least significant bit is position 0.

Returns

Returns 1 if the bit at Position is set, and 0 otherwise. Returns NaN if Position is out of range (0-63).

Example

BITWISE_GET_BIT(10, 1)

Returns 1, because the binary representation of 10 is 1010, and the bit at position 1 is set.

BITWISE_SET_BIT

BITWISE_SET_BIT


BITWISE_SET_BIT(N, Position, Value)

Sets a specific bit in an integer to a given value.

Parameters

  • N: The integer to modify.
  • Position: The position of the bit to set. The least significant bit is position 0.
  • Value: The value to set the bit to (either 1 or 0).

Returns

Returns the modified integer. Returns NaN if Position is out of range (0-63) or Value is not 0 or 1.

Example

BITWISE_SET_BIT(10, 2, 1)

Returns 14, because the binary representation of 10 is 1010, and setting the bit at position 2 results in 1110, which is 14.

BITWISE_AND

BITWISE_AND


BITWISE_AND(N1, N2)

Performs a bitwise AND operation on two integers.

Parameters

  • N1: The first integer.
  • N2: The second integer.

Returns

Returns the result of the bitwise AND operation.

Example

BITWISE_AND(10, 12)

Returns 8, because the binary representation of 10 is 1010 and the binary representation of 12 is 1100. The bitwise AND is 1000, which is 8.

BITWISE_OR

BITWISE_OR


BITWISE_OR(N1, N2)

Performs a bitwise OR operation on two integers.

Parameters

  • N1: The first integer.
  • N2: The second integer.

Returns

Returns the result of the bitwise OR operation.

Example

BITWISE_OR(10, 12)

Returns 14, because the binary representation of 10 is 1010 and the binary representation of 12 is 1100. The bitwise OR is 1110, which is 14.

BITWISE_XOR

BITWISE_XOR


BITWISE_XOR(N1, N2)

Performs a bitwise XOR operation on two integers.

Parameters

  • N1: The first integer.
  • N2: The second integer.

Returns

Returns the result of the bitwise XOR operation.

Example

BITWISE_XOR(10, 12)

Returns 6, because the binary representation of 10 is 1010 and the binary representation of 12 is 1100. The bitwise XOR is 0110, which is 6.

BITWISE_NOT

BITWISE_NOT


BITWISE_NOT(N)

Performs a bitwise NOT operation on an integer.

Parameters

  • N: The integer to operate on.

Returns

Returns the result of the bitwise NOT operation.

Example

BITWISE_NOT(10)

Returns -11, because the binary representation of 10 is 1010, inverting all of the bits, including the sign bit, is 0101. This is the two's complement representation of 11, with the sign bit flipped, resulting in -11.

BITWISE_SHIFT_LEFT

BITWISE_SHIFT_LEFT


BITWISE_SHIFT_LEFT(N, Bits)

Shifts the bits of an integer to the left.

Parameters

  • N: The integer to shift.
  • Bits: The number of bits to shift.

Returns

Returns the result of the left shift operation. Returns NaN if Bits is out of range (0-63).

Example

BITWISE_SHIFT_LEFT(10, 2)

Returns 40, because the binary representation of 10 is 1010, and shifting left by 2 bits results in 101000, which is 40.

BITWISE_SHIFT_RIGHT

BITWISE_SHIFT_RIGHT


BITWISE_SHIFT_RIGHT(N, Bits)

Shifts the bits of an integer to the right.

Parameters

  • N: The integer to shift.
  • Bits: The number of bits to shift.

Returns

Returns the result of the right shift operation. Returns NaN if Bits is out of range (0-63).

Example

BITWISE_SHIFT_RIGHT(10, 2)

Returns 2, because the binary representation of 10 is 1010, and shifting right by 2 bits results in 10, which is 2.