PLAYGROUND (experimental)

bit_count

Returns the number of set bits (population count) in n within specified width.
bit_count(
    n, 
    [width=8]
) -> NUMBER

Returns the number of set bits (population count) in n within specified width.

Syntaxe

var result = bit_count(255);      // Uses default width\nvar result2 = bit_count("0xFF", 0);  // Auto-detect (8 bits)

Arguments

NameTypeRequiredDefaultDescription
nyes-Number (int/float), hex string (0x... #...), or binary string (0b...)
width-8Bit width (8, 16, 32, 64...), or 0 for auto-detect