Vertical bitwise COUNT (sum of ones on the same position)

Viewed 475

Is there any efficient way to do COUNT of ones on the same position in many variables? The count function should fill array with sum of ones in corresponding bit number. For example we have following three variables (I use 8-bit variables to make it simple):

uint8_t a = 0xF;  // 0000 1111
uint8_t b = 0x3C; // 0011 1100
uint8_t c = 0xF0; // 1111 0000

int result[8];

// some operations ...

count << result[0] << result[1] << .... // prints 1122 2211

I found many solutions for summing the ones in whole single variable, but not for the above problem.

6 Answers
Related