©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The BIT_COUNT SQL Function in MySQL and MariaDB - Number of bits set

BIT_COUNTSyntax:BIT_COUNT(Integer)
Return value:INTEGER
Function type:Numeric function
Function Description

The BIT_COUNT() function returns the number of set bits of "Integer".

Character strings as arguments are interpreted as numbers.

The BIT_COUNT() function returns NULL if the value of "Integer" is NULL.

BIT_COUNT() returns 0 if "Integer" is not a numeric value.

SQL Examples for the BIT_COUNT function

 1
 2
 3
 4
 5
 6

SELECT BIT_COUNT(12202);
SELECT BIT_COUNT('1234');
SELECT BIT_COUNT('xy1234');
SELECT BIT_COUNT(null)

BIT_COUNT(12202)
int(2)
9
BIT_COUNT('1234')
int(2)
5
BIT_COUNT('xy1234')
int(2)
0
BIT_COUNT(null)
int(2)
NULL
The examples were created with the MyWAY SQL manager: Download

How to use the BIT_COUNT() function in MySQL and MariaDB databases

The BIT_COUNT() function in MySQL and MariaDB can be useful in various circumstances when working with binary data or when the number of bits set in a numeric value represented in binary format needs to be counted, for example when counting the number of flags set in a bit field or when evaluating the density of "1" in a binary value.
The BIT_COUNT() function always works with the binary representation of the value. If the input is not explicitly in binary format, it is interpreted as a decimal value and converted to binary before counting the set bits.
BINBIN_TO_UUIDBIT_ANDBIT_COUNTBIT_LENGTHBIT_ORBIT_XOR

Further MySQL und MariaDB SQL Numeric functions

CEILCEIL(Number)
More about CEIL Function

CEILINGCEILING(Number)
More about CEILING Function

CRC32CRC32(String)
More about CRC32 Function

CRC32CCRC32C([Parameter], String)

FLOORFLOOR(Number)
More about FLOOR Function

SIGNSIGN(Number)
More about SIGN Function

ABSABS(Number)
More about ABS Function

ACOSACOS(Number)
More about ACOS Function

ASINASIN(Number)
More about ASIN Function

ATANATAN(Number [, Number2])
More about ATAN Function

ATAN2ATAN2(Number [, Number2])
More about ATAN2 Function

COSCOS(Number)
More about COS Function

COTCOT(Number)
More about COT Function

DEGREESDEGREES(Number)
More about DEGREES Function

EXPEXP(Number)
More about EXP Function

LNLN(Number)
More about LN Function

LOGLOG([Base], Number)
More about LOG Function

LOG10LOG10(Number)
More about LOG10 Function

LOG2LOG2(Number)
More about LOG2 Function

MODMOD(Number, Divider)
More about MOD Function

POWPOW(Number, Exponent)
More about POW Function

POWERPOWER(Number, Exponent)
More about POWER Function

PIPI()
More about PI Function

RADIANSRADIANS(Number)
More about RADIANS Function

RANDRAND([Number])
More about RAND Function

ROUNDROUND(Number [, Decimals])
More about ROUND Function

SINSIN(Number)
More about SIN Function

SQRTSQRT(Number)
More about SQRT Function

TANTAN(Number)
More about TAN Function

TRUNCATETRUNCATE(Number, Decimals)
More about TRUNCATE Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the BIT_COUNT SQL function: mysql.com and mariadb.com and w3schools.com
Updated: 2023-09-24ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer