使用bitset做十进制、二进制的转换
例子一、十进制转换二进制
// bitset_bitset.cpp// compile with: /EHsc#include #include int main( ){ // Using the default constructor using namespace std; // Using the second member function bitset<20> b1 ( 5 ); cout << "The set of bits in bitset<5> b1( 5 ) is: ( " << b1 << " )." << endl; }
例子二、二进制转换十进制
#include #include void main(){ using namespace std; string bitval5 ("11110011011"); int length = strlen("11110011011"); bitset<11> b5 ( bitval5); cout << b5 << endl; cout << b5.to_ulong( ) << endl;} 例子三、支持指针#include #include void main(){ using namespace std; char p[] = "11110011011"; bitset<50> b5 ( p); cout << b5 << endl; cout << b5.to_ulong( ) << endl;}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~