In this C program we will Print the Binary Equivalent of a Decimal Number Using Bitwise Operator and then we will print the 2's Complement of the number on the screen. The Number will be taken from the user.color>
N:Bcolor> This Program is created for upto 8-bit binary number(
i.e: Range = 0 to 28-1 = 0 to 255
). input:
The Number (integers) (i.e. 15,10,128 etc.)output:
The binary equivalent of the decimal number and the 2's complement of the number, will be printed on the screen.CODE---->
#include
int main()
{
int n,i,x;
printf(" Please, Enter a Number : ");
scanf("%d",&n);
printf("\n The binary equivalent of the number : \n ");
for(i=7;i>=0;i--)
{
x=n&(1i);
if(x==0)
printf("0");
else
printf("1");
}
n=~n;
n=n+1;
printf("\n The 2's complement of the number :\n ");
for(i=7;i>=0;i--)
{
x=n&(1i);
if(x==0)
printf("0");
else
printf("1");
}
return 0;
}
color>