Topic: tech dcc pc src next

tech dcc pc src > binary.c

char Binary_CountBits(unsigned char in)
{
    const unsigned long long int conversion = 0x4332322132212110;
    return (char)(
      ((conversion >> (4 * (in & 0x0f))) & 0x0f) +
      ((conversion >> (4 * ((in & 0xf0) >> 4))) & 0x0f)
      );
}

char Binary_SetIndex(unsigned char bin, char setbit)
{
    char out = 0;
    char one_count = 0;
    for(; out < 8 && one_count < setbit; ++out)
    {
        if(bin & (1 << out))
            ++one_count;
    }
    out = (char)(out - 1);
    return out;
}