请注意: 下文中的一些示例引用自 [ClickHouse 社区文档](🔗) 并经过一定修改确保可以在 ByteHouse 中正常使用。

## bitTest

Takes any integer and converts it into [binary form].

**Syntax**



**Arguments**

  • `number` – Integer number.

  • `index` – Position of bit.

**Returned values**

Returns a value of bit at specified position.

Type: `UInt8` .

**Example**

For example, the number 43 in base-2 (binary) numeral system is 101011.

Query:



Result:



Another example:

Query:



Result:



## bitTestAll

Returns result of [logical conjuction] (AND operator) of all bits at given positions. The countdown starts from 0 from the right to the left.

The conjuction for bitwise operations:

0 AND 0 = 0

0 AND 1 = 0

1 AND 0 = 0

1 AND 1 = 1

**Syntax**



**Arguments**

  • `number` – Integer number.

  • `index1` , `index2` , `index3` , `index4` – Positions of bit. For example, for set of positions ( `index1` , `index2` , `index3` , `index4` ) is true if and only if all of its positions are true ( `index1``index2` , ⋀ `index3``index4` ).

**Returned values**

Returns result of logical conjuction.

Type: `UInt8` .

**Example**

For example, the number 43 in base-2 (binary) numeral system is 101011.

Query:



Result:



Another example:

Query:



Result:



## bitTestAny

Returns result of [logical disjunction](OR operator) of all bits at given positions. The countdown starts from 0 from the right to the left.

The disjunction for bitwise operations:

0 OR 0 = 0

0 OR 1 = 1

1 OR 0 = 1

1 OR 1 = 1

**Syntax**



**Arguments**

  • `number` – Integer number.

  • `index1` , `index2` , `index3` , `index4` – Positions of bit.

**Returned values**

Returns result of logical disjuction.

Type: `UInt8` .

**Example**

For example, the number 43 in base-2 (binary) numeral system is 101011.

Query:



Result:



Another example:

Query:



Result:



## bitmapAnd

Two bitmap and calculation, the result is a new bitmap.

**Syntax**



**Arguments**

  • `bitmap` – Bitmap object.

**Returned value**

  • The Bitmap object

**Example**



Result:



## bitmapAndCardinality

Two bitmap and calculation, return cardinality of type UInt64.

**Syntax**



**Arguments**

  • `bitmap` – Bitmap object.

**Returned value**

  • The cardinality in type `UInt64`.

Type:`Uint64`

**Example**



Result:



## bitmapAndnot

Two bitmap andnot calculation, the result is a new bitmap.

**Syntax**



**Arguments**

  • `bitmap` – Bitmap object.

**Returned value**

  • The Bitmap object

Type: `Bitmap object`.

**Example**



Result:



## bitmapAndnotCardinality

Two bitmap andnot calculation, return cardinality of type UInt64.

**Syntax**



**Arguments**

  • `bitmap` – Bitmap object.

**Returned value**

  • The cardinality in `UInt64`.

Type: `UInt64`

**Example**



Result:



## bitmapBuild

Build a bitmap from unsigned integer array.

**Syntax**



**Arguments**

  • `array` – Unsigned integer array.

**Returned value**

  • The bitmap object

Type: `Bitmap object`.

**Example**



Result:



## bitmapCardinality

Return bitmap cardinality of type UInt64.

**Syntax**



**Arguments**

  • `bitmap` – Bitmap object.

**Returned value**

  • The bitmap cardinality in type `UInt64`.

Type: `UInt64` .

**Example**



Result:



## bitmapContains

Checks whether the bitmap contains an element.

**Syntax**



**Arguments**

  • `haystack` – [Bitmap object], where the function searches.

  • `needle` – Value that the function searches. Type: [UInt32] .

**Returned values**

  • 0 — If `haystack` does not contain `needle` .

  • 1 — If `haystack` contains `needle` .

Type: `UInt8` .

**Example**



Result:



## bitmapHasAll

Analogous to `hasAll(array, array)` returns 1 if the first bitmap contains all the elements of the second one, 0 otherwise.

If the second argument is an empty bitmap then returns 1.

**Syntax**



**Arguments**

  • `bitmap` – Bitmap object.

**Returned value**

  • `1` , returns 1 if the first bitmap contains all the elements of the second one or If the second argument is an empty bitmap .

  • `0` , otherwise.

Type: `UInt8`

**Example**



Result:



## bitmapHasAny

Checks whether two bitmaps have intersection by some elements.

**Syntax**



If you are sure that `bitmap2` contains strictly one element, consider using the [bitmapContains] function. It works more efficiently.

**Arguments**

  • `bitmap*` – Bitmap object.

**Return values**

  • `1` , if `bitmap1` and `bitmap2` have one similar element at least.

  • `0` , otherwise.

**Example**



Result:



## bitmapMax

Return the greatest value of type UInt64 in the set, 0 if the set is empty.

**Syntax**



**Arguments**

  • `bitmap` – Bitmap object.

**Return values**

  • Return the greatest value of type UInt64 in the set.

Type: `UInt64`

**Example**



Result:



## bitmapMin

Return the smallest value of type UInt64 in the set, UINT32_MAX if the set is empty.

**Syntax**



**Arguments**

  • `bitmap` – Bitmap object.

**Return values**

  • Return the smallest value of type UInt64 in the set.

Type: `UInt64`

**Example**



Result:



## bitmapOr

Two bitmap or calculation, the result is a new bitmap.



**Arguments**

  • `bitmap` – Bitmap object.

**Returned value**

  • The Bitmap object

Type: `Bitmap object`.

**Example**



Result:



## bitmapOrCardinality

Two bitmap or calculation, return cardinality of type UInt64.

**Syntax**



**Arguments**

  • `bitmap` – Bitmap object.

**Return values**

  • Return or calculation result in cardinality.

Type:`UInt64`

**Example**



Result:



## bitmapSubsetInRange

Return subset in specified range (not include the range_end).

**Syntax**



**Arguments**

  • `bitmap` – [Bitmap object].

  • `range_start` – Range start point. Type: [UInt32].

  • `range_end` – Range end point (excluded). Type: [UInt32].

**Return values**

  • Return or calculation result.

Type:`array`

**Example**



Result:



## bitmapSubsetLimit

Creates a subset of bitmap with n elements taken between `range_start` and `cardinality_limit` .

**Syntax**



**Arguments**

  • `bitmap` – [Bitmap object].

  • `range_start` – The subset starting point. Type: [UInt32].

  • `cardinality_limit` – The subset cardinality upper limit. Type: [UInt32].

**Returned value**

  • The subset.

Type: `Bitmap object` .

**Example**

Query:



Result:



## bitmapToArray

Convert bitmap to integer array.

**Syntax**



**Arguments**

  • `bitmap` – Bitmap object.

**Returned value**

  • An array.

Type: `array` .

**Example**



Result:



## bitmapXor

Two bitmap xor calculation, the result is a new bitmap.



**Arguments**

  • `bitmap` – Bitmap object.

**Returned value**

  • The Bitmap object

Type: `Bitmap object`.

**Example**



Result:



## bitmapXorCardinality

Two bitmap xor calculation, return cardinality of type UInt64.

**Syntax**



**Arguments**

  • `bitmap` – Bitmap object.

  • **Returned value**

  • The Bitmap object

Type: `Bitmap object`.

**Example**



Result: