统计一个UINT32中2进制形式1的个数

UINT8 Calc_1_Number(UINT32 Val)
{
    UINT8 Num = 0;
    UINT8 TempVal  = Val;
    while(TempVal)
    {
        TempVal &= TempVal - 1;
        Num ++;
    }
    return Num;
}
This is not the fastest algorism.

n&n-1 can get rid of the lowest 1 in a binary integer.

你可能感兴趣的:(int)