我试图拿两个bitset物体,例如
a = 10010111
b = 01110010
Run Code Online (Sandbox Code Playgroud)
如果它们在相同的位置/索引中匹配,则从两个变量中删除位.所以我们会离开
a = 100xx1x1 = 10011
b = 011xx0x0 = 01100
Run Code Online (Sandbox Code Playgroud)
有没有办法实现这个目标?
您将需要编写自己的算法。像这样的事情可能会起作用:
std::bitset<size> mask = a^b; //A zero will be put in place where a and b do match
int offset = 0;
std::bitset<size> fin(0); //This will hold the answer for the a bitset
for (int x = 0; x < size; x++)
{
if (!mask[x]) //If the bit is zero we are keeping the bit
{
if (a[x])
{
fin.set(offset);
}
offset++;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
960 次 |
| 最近记录: |