bitset_count_ones()
Learn how to use the bitset_count_ones() function to return the number of set bits in the binary representation of a number.
Returns the number of set bits in the binary representation of a number.
Syntax
bitset_count_ones(
value)
Parameters
Name | Type | Required | Description |
---|---|---|---|
value | int | ✔️ | The value for which to calculate the number of set bits. |
Returns
Returns the number of set bits in the binary representation of a number.
Example
// 42 = 32+8+2 : b'00101010' == 3 bits set
print ones = bitset_count_ones(42)
Output
ones |
---|
3 |
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.