Roslyn Code Gems - Counting Bits
Posted by: K. Scott Allen,
on 19 Feb 2015 |
View original | Bookmarked: 0 time(s)
Back in the early days of computing, when machines were powered by coal-fired steam boilers the size of Liechtenstein, even the simplest operations were optimized by programmers toiling in the basements of university science buildings around the world. Simple operations like counting the number of “on” bits in a word.
Back then you couldn’t afford to use a naive approach...
unsigned int v; // count the number of bits set in v
unsigned int c; // c accumulates the total bits set in...