top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Are there rotate operation in c?

+1 vote
944 views
Are there rotate operation in c?
posted May 2, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
What is the meaning of rotation in the question?

2 Answers

+2 votes

example for unsigned 32-bit integer rotation

uint32_t val = . . . // this is the value being rotated
uint32_t num = . . .//this is the number of times the value needs to be rotated
uint32_t rol = (val << (32 - num)) | (val >> num); //left rotation
uint32_t ror = (val >> (32 - num)) | (val << num); //right rotation

answer May 3, 2016 by Lavanya L
where we use such type of rotation?
It is good practice question to get hands on bitwise operators, I'm not aware where its used
Thanks !
0 votes

Here is an example for unsigned 32-bit integers:

uint32_t val = ... // this is the value being rotated
uint32_t rol = (val << 1) | (val >> 31);
uint32_t ror = (val >> 1) | (val << 31);
answer May 2, 2016 by Rajan Paswan
Similar Questions
+2 votes

Does anyone know how to rotate a 2d matrix circularly for n times in suppose C language...? It would be a lot of help if you could explain with code.

Hint : Each time each row vector needs to be rotated one element to the right relative to the preceding row vector.

0 votes

Write a c program that rotate elements of an array by the value of configured number "n".
For example:
Input array[ ] = { 2, 3, 5, 6, 8, 9}
value of n = 2
Output array[] = { 5, 6, 8, 9, 2, 3}
I am looking for efficient program.

...