All Products
Search
Document Center

AnalyticDB:Bit string functions and operators

Last Updated:Aug 15, 2024

AnalyticDB for PostgreSQL is compatible with the bit string functions and operators of PostgreSQL. This topic describes the bit string functions and operators that are supported by AnalyticDB for PostgreSQL and provides examples on how to use the bit string functions and operators.

For information about the bit string functions and operators of PostgreSQL, see Bit String Functions and Operators.

Bit string operators

Bit string operators are a set of operators that can be used to manipulate bit strings. A bit string is a sequence of binary bits. Each bit can be 0 or 1. Bit string operators can be used to perform bit-level operations, such as bit flipping, bit counting, and bit mask generation.

Operator

Description

Example

Sample result

||

Concatenates two bit strings.

B'10001' || B'011'

10001011

&

Returns the bitwise AND of two bit strings.

B'10001' & B'01101'

00001

|

Returns the bitwise OR of two bit strings.

B'10001' | B'01101'

11101

#

Returns the bitwise XOR of two bit strings.

B'10001' # B'01101'

11100

~

Returns the bitwise NOT of a bit string.

~ B'10001'

01110

<<

Shifts the bits in the left bit string to the left by the number of positions specified by the right operand and fills the vacant positions with zeros.

B'10001' << 3

01000

>>

Shifts the bits in the left bit string to the right by the number of positions specified by the right operand and fills the vacant positions with zeros.

B'10001' >> 2

00100