Bitwise operators :
bitwise operators are used to operate the bit by bit.
1.convert a num
decimal to binary
#include<stdio.h>
main()
{
int i,n;
printf("enter the number\n");
scanf("%d",&n);
for(i=31;i>=0;i--)
{
if(n&1<<i)
printf("1");
else
printf("0");
}
}
Explanation :
This is 31st bit
00000000 00000000 0000000 00000000 ------
> this 0th bit.
In screen the
bits are printing in reverse order. So we go for left
shift.
Steps how to print:
1.cursor goes to 31st position.
2.prform logical and
3.prints
0
Next
00
Next
000
Next
01
like this.so printing on the screen from left to
right.so we go for left shift.
0 comments: