-4
爲什麼這個功能:C++的cout函數打印錯誤值
uint64_t rot_xor(uint64_t a1, uint64_t a2) {
int size = sizeof(a1)*4;
cout<<" "<<"size:"<<bitset<8>(size).to_string()<<" "<<size;
int shift;
uint64_t output = 0;
cout<<endl;
for (shift = 0; shift < size; shift++)
if(a1&(1<<shift)) {
output ^= (a2 << shift) | (a2 >> (size - shift));
cout << bitset<64>(output).to_string()<<endl;
}
return output;
}
打印輸出:
- :尺寸:00010000 20
- :0000000000000000000000000000000010110000110000011111001011111001
爲什麼不呢?你期望它打印什麼,你傳遞了什麼? –
你可以看到http://ideone.com/zkqMPO – AgentIvan
int size = sizeof(a1); cout << endl <<「size:」<(size).to_string()<<「」<< size; size = size * 4; cout <<「」<<「size:」<(size).to_string()<<「」<< size; 打印:尺寸:00001000 8尺寸:00100000 20 –
AgentIvan