75. WAP to rotate the number of bits in a number
#include<stdio.h>
void
main()
{
unsigned int num,rotate,r;
int i;
printf("WAP to rotate the number of
bits in a number\n");
printf("Enter a number : ");
scanf("%d",&num);
printf("Enter no of rotations :
");
scanf("%d",&rotate);
for(i=31;i>=0;i--)
printf("%d",num>>i&1);
printf("\n");
for(i=0;i<rotate;i++)
{
r=num&1;
num=num>>1;
if(r)
{
num=num|(1<<31);
}
}
for(i=31;i>=0;i--)
printf("%d",num>>i&1);
printf("\n");
}
Comments
Post a Comment