mramine364

decimal to binaire

Feb 1st, 2016
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void binaire(int n, string &r){
  7.     if(n>0){
  8.         binaire(n/2,r);
  9.         r.append(to_string(n%2));
  10.     }
  11. }
  12.  
  13. int main()
  14. {
  15.   int n = 456;
  16.   string r = "";
  17.   binaire(n,r);
  18.   cout << r << endl; // 111001000
  19.   return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment