Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何迭代唯一的(...000010000...)二进制掩码long long?我的意思是像面具一样0001, 0010, 0100, 1000
...000010000...
long long
0001, 0010, 0100, 1000
如果您的意思是每个掩码都设置一个位:
for (unsigned long long mask = 1; mask != 0; mask <<= 1) { // Do something with mask }
请注意,您必须使用unsigned才能在班次溢出时定义行为。
unsigned
我假设您并不是指所有可能的掩码值;遍历所有这些需要很长时间。