Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS-525: bitCount description EN, RU #9771

Merged
merged 8 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/en/query_language/functions/bit_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,44 @@ Result:
│ 0 │
└──────────────────────┘
```
## bitCount {#bitcount}

Calculates the number of bits set to one in the binary representation of a number.

**Syntax**

```sql
bitCount(x)
```

**Parameters**

- `x` — [Integer](../../data_types/int_uint.md) or [floating-point](../../data_types/float.md) number. The function uses the value representation in memory. It allows supporting floating-point numbers.

**Returned value**

- Number of bits set to one in the input number.

The function doesn't convert input value to a larger type ([sign extension](https://en.wikipedia.org/wiki/Sign_extension)). So, for example, `bitCount(toUInt8(-1)) = 8`.

Type: `UInt8`.

**Example**

Take for example the number 333. Its binary representation: 0000000101001101.

Query:

```sql
SELECT bitCount(333)
```

Result:

```text
┌─bitCount(333)─┐
│ 5 │
└───────────────┘
```

[Original article](https://clickhouse.tech/docs/en/query_language/functions/bit_functions/) <!--hide-->
40 changes: 40 additions & 0 deletions docs/ru/query_language/functions/bit_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,44 @@ SELECT bitTestAny(43, 4, 2)
└──────────────────────┘
```

## bitCount {#bitcount}

Подсчитывает количество равных единице бит в числе.

**Синтаксис**

```sql
bitCount(x)
```

**Параметры**

- `x` — [Целое число](../../data_types/int_uint.md) или [число с плавающей запятой](../../data_types/float.md). Функция использует представление числа в памяти, что позволяет поддержать числа с плавающей запятой.

**Возвращаемое значение**

- Количество равных единице бит во входном числе.

Функция не преобразует входное значение в более крупный тип ([sign extension](https://en.wikipedia.org/wiki/Sign_extension)). Поэтому, например, `bitCount(toUInt8(-1)) = 8`.

Тип: `UInt8`.

**Пример**

Возьмём к примеру число 333. Его бинарное представление — 0000000101001101.

Запрос:

```sql
SELECT bitCount(333)
```

Результат:

```text
┌─bitCount(100)─┐
│ 5 │
└───────────────┘
```

[Оригинальная статья](https://clickhouse.tech/docs/ru/query_language/functions/bit_functions/) <!--hide-->