[英]How to Assign a bitset to an unsigned char vector?
我正在使用具有一些十六进制值的无符号char向量。
std::vector<unsigned char> sync;
sync.push_back(0x50);
sync.push_back(0x51);
sync.push_back(0x52);
sync.push_back(0x53);
然后,使用位集将“ sync [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);
由于我通过参考传递了矢量,因此我想对其进行更改。 即,无论我对位集进行了什么更改,我也都希望将其提交给向量。 但是,我不确定如何将位集转换为未签名的char以及如何将其分配给我的向量,以便更新我的向量sync 。
调用manipulator.to_ulong()
。 (缩小到unsigned char
转换将是无害的。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.