简体   繁体   English

C++ cout函数打印

[英]C++ cout function print

Why this function:为什么这个功能:

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;
}

Print output:打印输出:


  1. : size:00010000 20 : 大小:00010000 20
  2. : 0000000000000000000000000000000010110000110000011111001011111001 : 0000000000000000000000000000000010110000110000011111001011111001

point 1第1点

If the question is why your program prints 20 as a result of what seems to be sizeof(uint64_t) * 4 instead of 32, well it's because a few lines before calling rot_xor there is a:如果问题是为什么你的程序打印 20 作为sizeof(uint64_t) * 4而不是 32 的结果,那是因为在调用rot_xor之前的几行中有一个:

cout << hex

In fact, the exact output as can be seen in the link you posted is事实上,在您发布的链接中可以看到确切的输出是

size:00100000 20

or 32 in binary and hexadecimal representation.或 32 的二进制和十六进制表示。

point 2第 2 点

I have no idea what your expected ouput should be like.我不知道您的预期输出应该是什么样的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM