The task is to return the number of bits set to true.
Here is my code:
The code is not working, since whenever I set _this->bits to a number, it returns me the wrong result. My question is: How could I fix this problem because the code looks perfect for me.Code:int cardinalityBS(PBitSet _this) { int s, counter = 0; for(s = 0; s < 31; s++) { counter += _this->bits & 1; _this->bits <<= 1; } return counter; }