All Products
Search
Document Center

Bitwise functions

Last Updated: Jan 15, 2019

bit_count(x, bits) → bigint

Counts the number of bits set in x (viewed as bits-bit signed integer) in two’s complement representation.

  1. SELECT bit_count(9, 64); -- 2
  2. SELECT bit_count(9, 8); -- 2
  3. SELECT bit_count(-7, 64); -- 62
  4. SELECT bit_count(-7, 8); -- 6

bitwise_and(x, y) → bigint

Returns AND of x and y in two’s complement representation.

bitwise_not(x) → bigint

Returns NOT of x in two’s complement representation.

bitwise_or(x, y) → bigint

Returns OR of x and y in two’s complement representation.

bitwise_xor(x, y) → bigint

Returns XOR of x and y in two’s complement representation.

See also bitwise_and_agg() and bitwise_or_agg().