我正在使用具有一些十六进制值的无符号字符向量。
std::vector<unsigned char> sync;
sync.push_back(0x50);
sync.push_back(0x51);
sync.push_back(0x52);
sync.push_back(0x53);
然后,使用位集,我将同步 [3]“变形”为 8 位表示。这是因为我需要破坏/切换其中的任何随机位。
srand(time(NULL));
int bitsetIndex= random()%8;
std::bitset<8> manipulator(v[3]); //v is the vector argument which takes "sync" vector
//by reference
manipulator.flip(bitsetIndex);
因为,我通过引用传递我的向量,所以我想对其进行更改。即我对我的位集所做的任何更改,我也想将它提交给向量。但是,我不确定如何将 bitset 转换为 unsigned char 以及如何将其分配给我的向量,以更新我的向量同步。