将“X”向左旋转4位

时间:2014-10-13 05:30:23

标签: bitwise-operators

/** 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 ;
  }

我想弄清楚如何移动4个最重要的位但是我不确定你将如何将它们旋转到最后 -Thanks

1 个答案:

答案 0 :(得分:1)

您搜索的内容为Circular shift operations

目前,你可以试试这个:

int rotl4(int x) {
    unsigned int y = x;
    return ((y>>28)|(y<<4));
}
相关问题