Collections:
BIT_COUNT() - Counting '1' in Binary String
How to count the number of '1' in a binary string using the BIT_COUNT() function?
✍: FYIcenter.com
BIT_COUNT(int) is a MySQL built-in function that
converts an unsigned integer to binary string and counts
the number of '1's in the string.
For example:
SELECT 64, BIN(64), BIT_COUNT(64); -- +----+---------+---------------+ -- | 64 | BIN(64) | BIT_COUNT(64) | -- +----+---------+---------------+ -- | 64 | 1000000 | 1 | -- +----+---------+---------------+ SELECT 1279, BIN(1279), BIT_COUNT(1279); -- +------+-------------+-----------------+ -- | 1279 | BIN(1279) | BIT_COUNT(1279) | -- +------+-------------+-----------------+ -- | 1279 | 10011111111 | 9 | -- +------+-------------+-----------------+ SELECT x'4142', BIN(x'4142'), BIT_COUNT(x'4142'); -- +---------+-----------------+--------------------+ -- | x'4142' | BIN(x'4142') | BIT_COUNT(x'4142') | -- +---------+-----------------+--------------------+ -- | AB | 100000101000010 | 4 | -- +---------+-----------------+--------------------+
Reference information of the BIT_COUNT() function:
BIT_COUNT(int): count Converts an unsigned integer to binary string and counts the number of '1's in the string. Arguments, return value and availability: int: Required. The unsigned integer to be examined. count: Return value. The number of '1's in the binary string representation. Available since MySQL 4.0.
⇒ CEIL() - Synonym for CEILING()
⇐ BIN() - Converting Integer to Binary String
2023-12-19, 1002🔥, 0💬
Popular Posts:
What is SQL Server Transact-SQL (T-SQL)? SQL Server Transact-SQL, also called T-SQL, is an extension...
Is PL/SQL Language Case Sensitive in Oracle? PL/SQL language is not case sensitive: Reserved words a...
What are single-byte character string data types supported in SQL Server Transact-SQL? Single-byte c...
How To Enter Unicode Character String Literals in SQL Server Transact-SQL? Unicode characters are mu...
How To Calculate Age in Days, Hours and Minutes in SQL Server Transact-SQL? On many Web sites, news ...