整数または Uint32 の最後の 6 ビットを取得する必要があります。たとえば、値が 183 の場合、最後の 6 ビットが必要110 111
です55
。
小さなコードを書きましたが、期待どおりに動作しません。私が間違っているところを指摘してもらえますか?
int compress8bitTolessBit( int value_to_compress, int no_of_bits_to_compress )
{
int ret = 0;
while(no_of_bits_to_compress--)
{
std::cout << " the value of bits "<< no_of_bits_to_compress << std::endl;
ret >>= 1;
ret |= ( value_to_compress%2 );
value_to_compress /= 2;
}
return ret;
}
int _tmain(int argc, _TCHAR* argv[])
{
int val = compress8bitTolessBit( 183, 5 );
std::cout <<" the value is "<< val << std::endl;
system("pause>nul");
return 0;
}