左移0点是什么意思?

Dat*_*sik 3 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);
                }
Run Code Online (Sandbox Code Playgroud)

我只想弄清楚他们使用的原因pkt << uint32(0),因为它们对我来说似乎完全是多余的.而且他们也经常使用它,这使得它更没意义.

为什么他们的代码是这样编写的?

mar*_*inj 11

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

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

    ByteBuffer& operator<<(uint8 value)
    {
        append<uint8>(value);
        return *this;
    }
Run Code Online (Sandbox Code Playgroud)

所以它不是0的移位,而是附加值0.

  • 哇,对于运营商重载来说,这看起来真的很糟糕.当你已经处于执行位操作的低级代码中时,使用逐位"&"运算符,十六进制文字和固定宽度无符号变量浮动,将位移运算符重载为除了位移之外的其他内容你需要什么让你的代码更容易理解:) (2认同)