【发布时间】:2026-02-13 09:05:02
【问题描述】:
我想左移一个特定的号码。其中一个特定的编号。次。我正在尝试这样的事情
//Left shift 3 1's by 5.
int a = 0;
a = 0b(111 << 5) ; //Error : unable to find numeric literal
// operator 'operator""b'
std::cout << a; //Should be 224
关于如何解决上述问题的任何建议?理想情况下,我想要这样的东西
int a = 0;
int noOfOnes = 3;
a = 0b(noOfOnes << 5);
我不确定如何在 C++ 中完成上述操作?
【问题讨论】:
-
以前知道吗?
-
@Deduplicator 我知道运行时需要多少个 1
-
为什么会有一个随机的
0b,而不是整数文字的一部分?
标签: c++ c++11 bit-manipulation bit-shift bitmask