) 保留符号(或最重要的数字,最左边的数字)取决于数字是有符号还是无符号 (假设一个字节的大小-6ren">
gpt4 book ai didi

c++ - "<<"(双尖括号)在 C/C++ 枚举中是什么意思?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:00:55 26 4
gpt4 key购买 nike

enum ofp10_port_state {

OFPPS10_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */
OFPPS10_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */
OFPPS10_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
OFPPS10_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */
OFPPS10_STP_MASK = 3 << 8 /* Bit mask for OFPPS10_STP_* values. */

};

最佳答案

它是一个左移位运算符。这意味着它将位向左移动指定的位数:

假设值为:

0x0F or 00001111
0x0F << 4 = 0xF0 or 11110000

在 Microsoft C++ 中,右移 (>>) 保留符号(或最重要的数字,最左边的数字)取决于数字是有符号还是无符号

(假设一个字节的大小):

signed integer (an int for example):
0x80 or 10000000
0x80 >> 7 = 11111111
0x10 or 00010000
0x10 >> 4 = 00000001
if its unsigned (a uint):
0x80 or 10000000
0x80 >> 7 = 00000001
0x10 or 00010000
0x10 >> 4 = 00000001

关于c++ - "<<"(双尖括号)在 C/C++ 枚举中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11055834/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com