感谢:http://blog.csdn.net/xiaofei2010/article/details/7434737

  以及:http://www.cnblogs.com/nzbbody/p/3504199.html

1. int转string(更多参见:http://www.cnblogs.com/nzbbody/p/3504199.html)

 1 #include <iostream>
 2 #include <sstream>
 3 using namespace std;
 4 
 5 int main()      {
 6     int aa = 30;
 7     stringstream ss;
 8     ss<<aa; 
 9     string s1 = ss.str();
10     cout<<s1<<endl; // 30
11 
12     string s2;
13     ss>>s2;
14     cout<<s2<<endl; // 30
15        
16     system("pause");
17     return 0;
18 }

 

2.10进制转2进制(更多参见:http://blog.csdn.net/xiaofei2010/article/details/7434737)

 1 //十进制转二进制
 2 #include<iostream>
 3 using namespace std;
 4 
 5 void printbinary(const unsigned int val)
 6 {
 7     for(int i = 16; i >= 0; i--)    {
 8         if(val & (1 << i))
 9             cout << "1";
10         else
11             cout << "0";
12     }
13 }
14 
15 int main()
16 {
17     printbinary(1024);
18     return 0;
19 }

 

相关文章:

  • 2022-12-23
  • 2021-11-03
  • 2021-12-11
  • 2021-12-08
  • 2021-11-20
  • 2021-12-23
  • 2022-02-22
  • 2021-08-11
猜你喜欢
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2022-02-28
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案