如何实现此Java函数:
public static int rotateLeft(int i, int distance) {
// Shift distances are mod 32 (JLS3 15.19), so we needn't mask -distance
return (i << distance) | (i >>> -distance);
}
答案 0 :(得分:1)
它与C相同,所以像
static int rotateLeft(int i, int distance) {
return (i << (distance % 32)) | ((unsigned int)i >> (32 - (distance % 32)));
}