The current page is about technical findings while I am working on various things. Information about certain cutting edge gadgets and mostly on SoC verification, ESL modeling, C/C++ cumbersome issues, SystemC updates are key areas !
Wednesday, October 15, 2008
Counting number of 1s in a number...
A simple and powerful algorithm....for calculating number of set bits....
#include
int CountSetbits(int num ) { int iCount = 0; while ( num ) { num &= (num-1) ; iCount++; }
return iCount;
}
int main() { int num = 7; printf("Number of set bits in a number %d = %d\n", num, CountSetbits(num)); }
No comments:
Post a Comment