2's compliment of decimal number to binary number program in c++
#include <iostream>
using namespace std;
int main()
{
int n,i,x;
cout<<" Please, Enter a Number : ";
cin>>n;
cout<<"\n The binary equivalent of the number : \n ";
for(i=3; i>=0; i--)
{
x=n&(1<<i);
if(x==0)
cout<<"0";
else
cout<<"1";
}
n=~n;
n=n+1;
cout<<"\n The 2's complement of the number :\n ";
for(i=3; i>=0; i--)
{
x=n&(1<<i);
if(x==0)
cout<<"0";
else
cout<<"1";
}
return 0;
}
***************""**"**
Algorithm step1 start
Step2 for(i=3; i>=0; i--) {
x=n&(1<<i);
if(x==0)
cout<<"0";
else
cout<<"1"; }
n=~n;
n=n+1;
Step3 stop
Comments
Post a Comment