# 消除尾一 下面的代码把一个整数的二进制表示的最右边的连续的1全部变成0 如果最后一位是0,则原数字保持不变。 **输入:** ``` 00000000000000000000000001100111 ``` **输出:** ``` 00000000000000000000000001100000 ``` **输入:** ``` 00000000000000000000000000001100 ``` **输出:** ``` 00000000000000000000000000001100 ``` 请你填补空白处的内容: ```cpp #include void f(int x) { int i; for (i = 0; i < 32; i++) printf("%d", (x >> (31 - i)) & 1); printf(" "); __________________ for (i = 0; i < 32; i++) printf("%d", (x >> (31 - i)) & 1); printf("\n"); } int main() { f(103); f(12); return 0; } ``` ## aop ### before ```cpp ``` ### after ```cpp ``` ## 答案 ```cpp x = x & (x + 1); ``` ## 选项 ### A ```cpp x = x & (x - 1); ``` ### B ```cpp x = x && (x - 1); ``` ### C ```cpp x = x && (x + 1); ```