programming-examples/c++/Basic/Decimal to Binary.cpp

19 lines
448 B
C++
Raw Normal View History

2019-11-18 14:44:36 +01:00
#include < iostream.h >
int main()
{
int n, c, k;
cout<<"Enter an integer in decimal number system\n";
cin>>n;
cout<<n<<"in binary number system is:\n";
for (c = 31; c >= 0; c--)
{
k = n >> c;
/*Right shift(Binary Divide by 2)*/
if (k & 1)//k is logically ANDed with 1
cout<<"1";
else
cout<<"0";
}
return 0;
}