72. To reverse binary of a number (Method 2)
#include<stdio.h>
void
main()
{
int num,rev,i,j,n1,n2;
printf("To reverse binary of a
number \n");
printf("Enter a number : ");
scanf("%d",&num);
for(i=31;i>=0;i--)
printf("%d",num>>i&1);
printf("\n");
for(i=0,j=31;i<=31;i++,j--)
{
if(n1=num>>i&1)
rev=rev|1<<j;
}
for(i=31;i>=0;i--)
printf("%d",rev>>i&1);
printf("\n");
}
Comments
Post a Comment