c++ - 左移0有什么意义?

标签 c++

我目前正在尝试为一个开源服务器实现一个谷歌验证器,他们有这么一小段代码

  if (securityFlags & 0x01)               // PIN input
                {
                    pkt << uint32(0);
                    pkt << uint64(0) << uint64(0);      // 16 bytes hash?
                    // This triggers the 2 factor authenticator entry to popup on the client side

                }

                if (securityFlags & 0x02)               // Matrix input
                {
                    pkt << uint8(0);
                    pkt << uint8(0);
                    pkt << uint8(0);
                    pkt << uint8(0);
                    pkt << uint64(0);
                }

                if (securityFlags & 0x04)               // Security token input
                {
                    pkt << uint8(1);
                }

我只是想弄清楚他们为什么使用 pkt << uint32(0) ,因为它们对我来说似乎完全多余。而且他们还多次使用它,这更没有意义。

知道为什么他们的代码是这样写的吗?

最佳答案

operator<< 为 ByteBuffer 重载(这是一个 pkt 类型),看起来如下:

https://github.com/mangostwo/server/blob/b8ce9508483375a36699c309bce36810c4548007/src/shared/ByteBuffer.h#L138

    ByteBuffer& operator<<(uint8 value)
    {
        append<uint8>(value);
        return *this;
    }

所以它不是移动 0,而是附加值 0。

关于c++ - 左移0有什么意义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41837395/

相关文章:

c++ - 为什么接受用户输入后我的程序由于访问冲突而崩溃?

c++ - 在函数 c++ 中更改给定的函数参数

java - 如何制作人脸检测中侧面的xml文件

c++ - MPI:Waitany 对 ibcast 调用没有反应

c++ - OpenGL重启场景

c++ - c++(98) STL set 是否可以散列一个 int 数组,然后检查该数组是否存在于集合中

c++ - QTableWidget 显示滚动条

c++ - OpenCV:minMaxIdx 之后的堆栈损坏

c++ - boost 库中是否有直接生成 png 文件而不是点的函数?

c++ - double C++