limpingricky

binary

Oct 9th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. /*binary*/
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. void nbr(unsigned br1, int i);
  6.  
  7. int main(){
  8.     unsigned a;
  9.     cout << "a: " << endl;
  10.     cin >> a;
  11.     nbr(a, 1);
  12.     return 0;
  13. }
  14.  
  15. void nbr(unsigned br1, int i){
  16.     unsigned br2;
  17.     br2 = br1;
  18.     br1 = br1 >> 1;
  19.     br1 = br1 << 1;
  20.     if(br1 != br2){
  21.         if(i <= 8)
  22.             nbr(br1 >> 1, ++i);
  23.         cout << "1";
  24.         return;
  25.     }
  26.     else{
  27.         if(i <= 8)
  28.             nbr(br1 >> 1, ++i);
  29.         cout << "0";
  30.         return;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment