8.6Bitwise Functions

8.6.1BIN_AND()

Bitwise AND

Result typeinteger type (the widest type of the arguments)

Note

SMALLINT result is returned only if all the arguments are explicit SMALLINTs or NUMERIC(n, 0) with n <= 4; otherwise small integers return an INTEGER result.

Syntax

  |BIN_AND (number, number [, number ...])

Table 8.64BIN_AND Function Parameters
ParameterDescription

number

A number of an integer type

Returns the result of the bitwise AND operation on the argument(s).

See alsoSection 8.6.3, “BIN_OR(), Section 8.6.6, “BIN_XOR()

8.6.2BIN_NOT()

Bitwise NOT

Result typeinteger type matching the argument

Note

SMALLINT result is returned only if all the arguments are explicit SMALLINTs or NUMERIC(n, 0) with n <= 4; otherwise small integers return an INTEGER result.

Syntax

  |BIN_NOT (number)

Table 8.65BIN_NOT Function Parameter
ParameterDescription

number

A number of an integer type

Returns the result of the bitwise NOT operation on the argument, i.e. one’s complement.

See alsoSection 8.6.3, “BIN_OR(), Section 8.6.6, “BIN_XOR() and others in this set.

8.6.3BIN_OR()

Bitwise OR

Result typeinteger type (the widest type of the arguments)

Note

SMALLINT result is returned only if all the arguments are explicit SMALLINTs or NUMERIC(n, 0) with n <= 4; otherwise small integers return an INTEGER result.

Syntax

  |BIN_OR (number, number [, number ...])

Table 8.66BIN_OR Function Parameters
ParameterDescription

number

A number of an integer type

Returns the result of the bitwise OR operation on the argument(s).

See alsoSection 8.6.1, “BIN_AND(), Section 8.6.6, “BIN_XOR()

8.6.4BIN_SHL()

Bitwise left-shift

Result typeBIGINT or INT128 depending on the first argument

Syntax

  |BIN_SHL (number, shift)

Table 8.67BIN_SHL Function Parameters
ParameterDescription

number

A number of an integer type

shift

The number of bits the number value is shifted by

Returns the first argument bitwise left-shifted by the second argument, i.e. a << b or a·2b.

See alsoSection 8.6.5, “BIN_SHR()

8.6.5BIN_SHR()

Bitwise right-shift with sign extension

Result typeBIGINT or INT128 depending on the first argument

Syntax

  |BIN_SHR (number, shift)

Table 8.68BIN_SHR Function Parameters
ParameterDescription

number

A number of an integer type

shift

The number of bits the number value is shifted by

Returns the first argument bitwise right-shifted by the second argument, i.e. a >> b or a/2b.

The operation performed is an arithmetic right shift (x86 SAR), meaning that the sign of the first operand is always preserved.

See alsoSection 8.6.4, “BIN_SHL()

8.6.6BIN_XOR()

Bitwise XOR

Result typeinteger type (the widest type of the arguments)

Note

SMALLINT result is returned only if all the arguments are explicit SMALLINTs or NUMERIC(n, 0) with n <= 4; otherwise small integers return an INTEGER result.

Syntax

  |BIN_XOR (number, number [, number ...])

Table 8.69BIN_XOR Function Parameters
ParameterDescription

number

A number of an integer type

Returns the result of the bitwise XOR operation on the argument(s).

See alsoSection 8.6.1, “BIN_AND(), Section 8.6.3, “BIN_OR()