githubEdit

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)

Argument
Type
Description

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 myTable
value

8

bitOr / bit_or

Performs a bitwise OR operation on two values.

Signature

bitOr(a, b) bit_or(a, b)

Argument
Type
Description

a

INT or LONG

First value

b

INT or LONG

Second value

Returns: INT (if both INT) or LONG (if any LONG)

Usage Examples

value

12

bitXor / bit_xor

Performs a bitwise XOR (exclusive OR) operation on two values.

Signature

bitXor(a, b) bit_xor(a, b)

Argument
Type
Description

a

INT or LONG

First value

b

INT or LONG

Second value

Returns: INT (if both INT) or LONG (if any LONG)

Usage Examples

value

6

bitNot

Performs a bitwise NOT operation, inverting all bits of a value.

Signature

bitNot(a)

Argument
Type
Description

a

INT or LONG

Value to invert

Returns: INT (if INT) or LONG (if LONG)

Usage Examples

value

-1

bitMask

Creates a bitmask with a single bit set at position n.

Signature

bitMask(n)

Argument
Type
Description

n

INT

Bit position (0-indexed)

Returns: INT

Usage Examples

value

1

value

8

bitShiftLeft

Performs a left bit shift operation.

Signature

bitShiftLeft(a, n)

Argument
Type
Description

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

value

4

bitShiftRight

Performs an arithmetic right bit shift operation (sign-extending).

Signature

bitShiftRight(a, n)

Argument
Type
Description

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

value

2

bitShiftRightUnsigned / bitShiftRightLogical

Performs a logical (unsigned) right bit shift operation, filling with zeros.

Signature

bitShiftRightUnsigned(a, n) bitShiftRightLogical(a, n)

Argument
Type
Description

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

value

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)

Argument
Type
Description

a

INT or LONG

Value to extract from

n

INT

Bit position (0-indexed)

Returns: INT (always, regardless of input type)

Usage Examples

value

1

value

0

Combined Usage Example

Last updated

Was this helpful?