Counts the bits set in an integral or boolean value. Integral values are widened to longs first, so a negative value also counts its sign extension. True counts as 1 and false as 0.
Expression categories: Binary
Declared arguments
Expression: The value whose set bits to count. Expression<Boolean | Byte | Integer | Long | Short>
Output type:Integer
Examples
Example 1: Base case
Description: A negative integer counts the 32 extra bits of its sign extension to a long.
Argument values:
Expression:value
value
Output
7
3
0
0
-1
64
Example 2: Base case
Description: A boolean counts as 1 if true and 0 if false.