countSetBits method
Returns the number of set bits in this
, assuming a bitWidth
this
.
NOTE:
bitWidth
is not validated. See Integral.bitsSet.
Implementation
int countSetBits(int bitWidth) {
var count = 0;
for (var i = 0; i < bitWidth; i++) {
if (this & (1 << i) != 0) {
count++;
}
}
return count;
}