Bitwise Functions
This section contains reference documentation for bitwise scalar functions.
Bitwise scalar functions perform bitwise operations on INT and LONG integer types.
Type Behavior
INT inputs: When all arguments are INT, the result is INT
Mixed or LONG inputs: When any argument is LONG, the result is LONG
bitExtract: Always returns INT, regardless of input types
bitAnd / bit_and
Performs a bitwise AND operation on two values.
Signature
bitAnd(a, b) bit_and(a, b)
a
INT or LONG
First value
b
INT or LONG
Second value
Returns: INT (if both INT) or LONG (if any LONG)
Usage Examples
SELECT bitAnd(12, 10) AS value
FROM myTable8
bitOr / bit_or
Performs a bitwise OR operation on two values.
Signature
bitOr(a, b) bit_or(a, b)
a
INT or LONG
First value
b
INT or LONG
Second value
Returns: INT (if both INT) or LONG (if any LONG)
Usage Examples
12
bitXor / bit_xor
Performs a bitwise XOR (exclusive OR) operation on two values.
Signature
bitXor(a, b) bit_xor(a, b)
a
INT or LONG
First value
b
INT or LONG
Second value
Returns: INT (if both INT) or LONG (if any LONG)
Usage Examples
6
bitNot
Performs a bitwise NOT operation, inverting all bits of a value.
Signature
bitNot(a)
a
INT or LONG
Value to invert
Returns: INT (if INT) or LONG (if LONG)
Usage Examples
-1
bitMask
Creates a bitmask with a single bit set at position n.
Signature
bitMask(n)
n
INT
Bit position (0-indexed)
Returns: INT
Usage Examples
1
8
bitShiftLeft
Performs a left bit shift operation.
Signature
bitShiftLeft(a, n)
a
INT or LONG
Value to shift
n
INT
Number of positions to shift
Returns: INT (if a is INT) or LONG (if a is LONG)
Usage Examples
4
bitShiftRight
Performs an arithmetic right bit shift operation (sign-extending).
Signature
bitShiftRight(a, n)
a
INT or LONG
Value to shift
n
INT
Number of positions to shift
Returns: INT (if a is INT) or LONG (if a is LONG)
Usage Examples
2
bitShiftRightUnsigned / bitShiftRightLogical
Performs a logical (unsigned) right bit shift operation, filling with zeros.
Signature
bitShiftRightUnsigned(a, n) bitShiftRightLogical(a, n)
a
INT or LONG
Value to shift
n
INT
Number of positions to shift
Returns: INT (if a is INT) or LONG (if a is LONG)
Usage Examples
2147483647
bitExtract / extractBit
Extracts the bit at position n, returning 1 if the bit is set, 0 otherwise.
Signature
bitExtract(a, n) extractBit(a, n)
a
INT or LONG
Value to extract from
n
INT
Bit position (0-indexed)
Returns: INT (always, regardless of input type)
Usage Examples
1
0
Combined Usage Example
Last updated
Was this helpful?

