Trying to flip the order of bits in std::bitset

断了今生、忘了曾经 提交于 2019-12-02 02:32:59

I don't know of a single algorithm that does this but you can use a combination of bitset::to_string and std::reverse to do this.

A minimal example.

#include "Register.h"
#include <algorithm>
#include <bitset>
#include <iostream>
#include <string>

int main() {
  vpc::Byte register_ = 169;
  std::cout << register_ << std::endl;

  auto str = register_.to_string();
  std::reverse(str.begin(), str.end());
  auto x = vpc::Byte(str);
  std::cout << x << std::endl;

  return 0;
}

See Demo Here.

Output:

10101001
10010101

This method can be used with any of the other bitset types you have defined.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!