我必须将int向右移动一个位置并将其返回
在Java中我只能返回n >> 1;
这可能在C?
我们给出的方法如下
// Return n after a right circular 1-bit shift
unsigned int right_circular_shift_1(unsigned int n) {
Run Code Online (Sandbox Code Playgroud)
小智 10
C没有循环移位,所以我想练习就是实现它.左循环移位的方法是:
- get the current leftmost bit and save it
- shift the number leftwards by one
- or the saved bit in at the rightmost bit position
Run Code Online (Sandbox Code Playgroud)
对于正确的循环移位:
- get the current rightmost bit and save it
- shift the number rightwards by one
- or the saved bit in at the leftmost bit position
Run Code Online (Sandbox Code Playgroud)