Presto provides the following bitwise functions:

Function Syntax Description
bit_count bit_count(x, bits) → bigint Returns the number of bits set in x at position 1 in two's complement representation.
bitwise_and bitwise_and(x, y) → bigint Bitwise AND function
bitwise_not bitwise_not(x) → bigint Bitwise NOT function
bitwise_or bitwise_or(x, y) → bigint Bitwise OR function
bitwise_xor bitwise_xor(x, y) → bigint Bitwise XOR function
bitwise_and_agg bitwise_and_agg(x) → bigint Returns the bitwise AND of all input values in x, which is an array.
bitwise_or_agg bitwise_or_agg(x) → bigint Returns the bitwise OR of all input values in x, which is an array.

Examples:

SELECT bit_count(9, 64); -- 2
SELECT bit_count(9, 8); -- 2
SELECT bit_count(-7, 64); -- 62
SELECT bit_count(-7, 8); -- 6