You need to enable JavaScript to run this app.
ByteHouse Cloud Data Warehouse Version

ByteHouse Cloud Data Warehouse Version

Copy page
Download PDF
Function reference
Bitwise operation functions
Copy page
Download PDF
Bitwise operation functions

bitTest

Take any integer and convert it to [binary form].
Syntax

SELECT bitTest(number, index)

Param

  • number – Integer.
  • index – Bit position.

Return value
Returns the bit value at the specified position.
Type: UInt8.
Example
For example, the number 43 in the binary number system is 101011.

SELECT bitTest(43, 1);

Result:

┌─bitTest(43, 1)─┐ 
│ 1              │ 
└────────────────┘

Another example:

SELECT bitTest(43, 2);

Result:

┌─bitTest(43, 2)─┐ 
│ 0              │ 
└────────────────┘

bitTestAll

Returns the result of [logical AND] (AND operator) for all bits at the given positions. From right to left, counting backwards starting from 0.
Combination of bitwise operations:
0 and 0 = 0
0 and 1 = 0
1 and 0 = 0
1 and 1 = 1
Syntax

SELECT bitTestAll(number, index1, index2, index3, index4, ...)

Param

  • number – Integer.
  • index1, index2, index3, index4 – Bit position. For example, for the set of positions (index1, index2, index3, index4), the result is true only when all positions are true (index1 ⋀ index2 ⋀ index3 ⋀ index4).

Return value
Returns the result of the logical conjunction.
Type: UInt8.
Example
For example, the number 43 in the binary number system is 101011.

SELECT bitTestAll(43, 0, 1, 3, 5);

Result:

┌─bitTestAll(43, 0, 1, 3, 5)─┐ 
│ 1                          │ 
└────────────────────────────┘

Another example:

SELECT bitTestAll(43, 0, 1, 3, 5, 2);

Result:

┌─bitTestAll(43, 0, 1, 3, 5, 2)─┐ 
│ 0                             │ 
└───────────────────────────────┘

bitTestAny

Returns the result of [logical OR] (OR operator) for all bits at the given positions. From right to left, counting backwards starting from 0.
Disjunction of bitwise operations:
0 or 0 = 0
0 or 1 = 1
1 or 0 = 1
1 or 1 = 1
Syntax

SELECT bitTestAny(number, index1, index2, index3, index4, ...)

Param

  • number – Integer.
  • index1, index2, index3, index4 – Bit position.

Return value
Returns the result of the logical disjunction.
Type: UInt8.
Example
For example, the number 43 in the binary number system is 101011.

SELECT bitTestAny(43, 0, 2);

Result:

┌─bitTestAny(43, 0, 2)─┐ 
│ 1                    │ 
└──────────────────────┘

Another example:

SELECT bitTestAny(43, 4, 2);

Result:

┌─bitTestAny(43, 4, 2)─┐ 
│ 0                    │ 
└──────────────────────┘
Last updated: 2026.03.31 16:13:53