Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

1's Complement using Bitwise Operator in C-Language




In this C program we will Print the Binary Equivalent of a Decimal Number Using Bitwise Operator and then we will print the 1'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 1'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;
printf("\n The 1'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;
}





Don't just read, write it, run it.....color>

RESULT:color>





This post first appeared on ProgramJoy.blogspot.com, please read the originial post: here

Share the post

1's Complement using Bitwise Operator in C-Language

×

Subscribe to Programjoy.blogspot.com

Get updates delivered right to your inbox!

Thank you for your subscription

×