1. Description
Calculates the number of 1 in a binary integer
2. Example
11111110100 -> 8
001011010 -> 4
3. Code
[restabs alignment="osc-tabs-right" responsive="true" icon="true" text="More" seltabcolor="#fdfdfd" seltabheadcolor="#000" tabheadcolor="blue"]
[restab title="C" active="active"]
int countBit(int x) { int count = 0; while(x != 0) { count++; x &= (x - 1); } return count; }
[/restab]
[/restabs]
Comments | NOTHING