BIT_COUNT()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Returns the number of bits set in the given argument.
USAGE
BIT_COUNT(number)
Argument Name | Description |
---|---|
| The number whose bits are counted |
DETAILS
BIT_COUNT()
is a bitwise function that returns the number of binary bits set in the given number.
The calculation is done with unsigned 64-bit precision.
A NULL
is returned if the argument is NULL
.
EXAMPLES
CREATE TABLE bitcount_example (
example BIGINT
);
INSERT INTO bitcount_example VALUES
(42), (101), (99), (13), (64), (86);
SELECT example, BIN(example), BIT_COUNT(example)
FROM bitcount_example;
+---------+--------------+--------------------+
| example | BIN(example) | BIT_COUNT(example) |
+---------+--------------+--------------------+
| 42 | 101010 | 3 |
| 101 | 1100101 | 4 |
| 99 | 1100011 | 4 |
| 13 | 1101 | 3 |
| 64 | 1000000 | 1 |
| 86 | 1010110 | 4 |
+---------+--------------+--------------------+