counting 1's in a binary byte

This is a discussion on counting 1's in a binary byte within the C++ Programming forums, part of the General Programming Boards category; basically i need to know how to count the 1's in example: 10110001
then output : 4 (for this example)
...

I would strongly looking into the <bitset> header. It's great! You can do things like

int i = 0;
bitset<8> thing;

and I can't remember how (haven't used it in a long time), but you can assign the value of a variable to the 'thing' variable. And there's a counting function to could the number of 1's etc. the <8> specifies it's eight bts (EDIT :: Had bytes written there, whoops. It's 8 BITS!).

is there a way to get rid of the commers in the array so for example... 1,1,1,1,0,0,0,0 is inputed as 11110000 and still reads 4 1s ? i tryed it without commers and it reads there is only 1 1's in the byte