1
私はここに何か愚かなものがないようです。BitsetプログラムC++
int main()
{
/*
bitset<sizeof(int)*8> bisetInt(64);
cout<<"Sizeof is "<<sizeof(int)<<endl;
for(int i=0;i< sizeof(int)*8;i++)
cout<<bisetInt[i]<<endl;
//cout<<"no bits set are "<<bisetInt.count()<<endl;
*/
int num = 5;
int x = 1;
for (int i = 0;i < 5; i++)
{
x = x<<i;
cout<< (num & x)<<endl;
cout<<"value of x is "<<x<<endl;
}
return 0;
}
出力:
1
value of x is 1
0
value of x is 2
0
value of x is 8
0
value of x is 64
0
value of x is 1024
私はそれだけですべてのxの値を変更しない
x = x<<i; //not this
x<<i;//rather this
だと思った瞬間のために。なぜxが2→8-> 64にジャンプしているのか分かりません。
乾杯!
Doh!ありがとうございました :) –