-2
/** The result of rotating X left by 4 bits. To rotate left means
 * that the 4 most significant bits become the 4 least significant  
 * and all other bits move left by 4. For example,  
 * rotl4(0x12345678) is 0x23456781. */
  int rotl4(int x) {
     return ;
  }

I am trying to figure out how to shift the 4 most significant bits but I am not sure on how would you rotate them to the end -Thanks

Edwan
  • 39
  • 7

1 Answers1

1

What you search for is Circular shift operations

For now, you can try this:

int rotl4(int x) {
    unsigned int y = x;
    return ((y>>28)|(y<<4));
}
Community
  • 1
  • 1
raj raj
  • 1,932
  • 1
  • 14
  • 15
  • Thanks! Can you please explain your reasoning? – Edwan Oct 13 '14 at 06:07
  • @Edwan most of the bits go 4 to the left, the top 4 have to go all the way to the right. Probably sounds obvious, but that's just what the code is saying too. – harold Oct 13 '14 at 19:37