Converting string of 1s and 0s into binary value

前端 未结 6 924
梦如初夏
梦如初夏 2020-11-27 07:06

I\'m trying to convert an incoming sting of 1s and 0s from stdin into their respective binary values (where a string such as \"11110111\" would be converted to 0xF7). This s

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 08:01

    You can use Boost Dynamic Bitset:

    boost::dynamic_bitset<>  x(std::string("01011"));
    std::cout << x << ":" << x.to_ulong() << std::endl;
    

提交回复
热议问题