#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
int n;
scanf("%d",&n);
int bin[20]; // Binary Equivalent Number of 'n'
int k = 0;
int i;
while(n != 0)
{
bin[k] = n % 2; // Computing Binary Equivalent Number of 'n' in Reverse Order
k++;
n = n/2 ;
}
printf("\n\n");
for(i=k-1;i>=0;i--)
printf(" %d",bin[i]);
for(i=0;i<k;i++)
bin[i] = (bin[i]==1)?0:1; // Complementing Binary Equivalent Number of 'n'
printf("\n\n");
for(i=k-1;i>=0;i--)
printf(" %d",bin[i]);
i = 0;
n = 0;
int prod = 1;
while(i<k)
{
printf(" %d",prod);
n = n + (bin[i]*prod); // Computing 'n' from Binary Equivalent Number
prod *= 2;
++i;
}
printf("\n %d",n);
getch();
}
No comments:
Post a Comment