如何将bitset分配给未签名的char矢量
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);
然后,使用bitset i"变形"同步[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);
由于我是通过引用传递我的向量,所以我想对其进行更改。IE。无论我对BITSet做过什么更改,我也都想将其提交给向量。但是,我不确定如何将BITSet转换为未签名的字符以及如何将其分配给我的向量,以更新我的向量同步。
调用manipulator.to_ulong()
。(向您的unsigned char
的狭窄转换将是无害的。)
相关文章:
- 打印标准::<char>不带无关字符的矢量
- 将.txt文件存储到 char* 2d 矢量C++中
- 哪一个更适合存储字符、矢量<char>或字符串?
- 如何在矢量中显示特定项目<char>?(C++)
- 将 char* 推送到矢量时出现问题,但在每次迭代后,它会将指向相同值缓冲区的指针添加到矢量中
- C++将结构强制转换为 std::矢量<char>内存对齐
- 保存一个未签名的char矢量
- 如何将bitset分配给未签名的char矢量
- 分类char矢量
- 将矢量<char>复制到 2D 矢量 <string> c++
- 将char阵列向量施加到POD矢量
- 字符串流到矢量<char>抛出 std::bad_alloc
- 将矢量<char>转换为常量字符* 和字符串
- 如何将char的矢量转换为字符串流
- 矢量<char>优于字符串的好处?
- 矢量<string>还是矢量<矢量<char>>?
- 如何使用<char>分度将矢量拆分为字符串
- 如何从矢量中删除元素<char>?
- C++字符串与矢量<char>
- 将标准::字符串转换为标准::矢量<char>