Advertisement
filomancio

Decimal to Binary conversion

Mar 1st, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     unsigned int a,t,mask=0;
  6.     mask=~mask;
  7.     cout<<"Insert an integer number <= "<<mask<<endl;
  8.     cin>>a;
  9.     mask=mask<<(sizeof(mask)*8-1);
  10.     while(mask!=0)
  11.     {
  12.         t=a&mask;
  13.         if(t==0)
  14.             cout<<'0';
  15.         else
  16.             cout<<'1';
  17.         mask=mask>>1;
  18.     }
  19.     cout<<endl;
  20.     system("PAUSE");
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement