Go through this program and execute it you will get the result
#include
#define INT_BITS 32
/* Driver program to test below functions */
int main()
{
int n = 16;
int d = 2;
printf(“Left Rotation of %d by %d is “, n, d);
printf(“%d”, leftRotate(n, d));
printf(“\nRight Rotation of %d by %d is “, n, d);
printf(“%d”, rightRotate(n, d));
getchar();
}
/*Function to left rotate n by d bits*/
int leftRotate(int n, unsigned int d)
{
/* In n<<d, last d bits are 0. To put first 3 bits of n at
last, do bitwise or of n<>(INT_BITS – d) */
return (n <> (INT_BITS – d));
}
/*Function to right rotate n by d bits*/
int rightRotate(int n, unsigned int d)
{
/* In n>>d, first d bits are 0. To put last 3 bits of at
first, do bitwise or of n>>d with n <> d)|(n << (INT_BITS – d));
}
use array in this program as bits
I guess Shift Left and Shift Right may help. <> ?
Go through this program and execute it you will get the result
#include
#define INT_BITS 32
/* Driver program to test below functions */
int main()
{
int n = 16;
int d = 2;
printf(“Left Rotation of %d by %d is “, n, d);
printf(“%d”, leftRotate(n, d));
printf(“\nRight Rotation of %d by %d is “, n, d);
printf(“%d”, rightRotate(n, d));
getchar();
}
/*Function to left rotate n by d bits*/
int leftRotate(int n, unsigned int d)
{
/* In n<<d, last d bits are 0. To put first 3 bits of n at
last, do bitwise or of n<>(INT_BITS – d) */
return (n <> (INT_BITS – d));
}
/*Function to right rotate n by d bits*/
int rightRotate(int n, unsigned int d)
{
/* In n>>d, first d bits are 0. To put last 3 bits of at
first, do bitwise or of n>>d with n <> d)|(n << (INT_BITS – d));
}