L
lovecreatesbea...
I read some old posts, they did this task in very different ways. How
is the following one?
Thank you for your time.
/
*******************************************************************************
* Count the bit set in an integer. eg. integer: 0x01101011, bitcount:
5
******************************************************************************/
int bitcount(int i)
{
unsigned int cnt = 0, MASK;
for (MASK = 0x1; MASK != 0; MASK <<= 1)
if ((MASK & i) == MASK)
cnt++;
return cnt;
}
is the following one?
Thank you for your time.
/
*******************************************************************************
* Count the bit set in an integer. eg. integer: 0x01101011, bitcount:
5
******************************************************************************/
int bitcount(int i)
{
unsigned int cnt = 0, MASK;
for (MASK = 0x1; MASK != 0; MASK <<= 1)
if ((MASK & i) == MASK)
cnt++;
return cnt;
}