#include<stdio.h>int main(){ unsigned int num,temp1,temp2,temp3,temp4,k,num1,num2; int i = 0; PRintf("Please enter an integer:/n"); scanf("%d",&num); temp1 = num; temp2 = num; //分別向左右移一位再異或,即可得到相鄰兩位異或的結(jié)果 temp1 <<= 1; //左移一位在加上溢出的 temp2 >>= 31; num1 = temp1 + temp2; temp3 = num; temp4 = num; temp3 >>= 1; //右移一位在加上舍棄的 temp4 <<= 31; num2 = temp3 + temp4; num = num1 ^ num2; //相鄰兩位異或 printf("%ud",num);}
新聞熱點
疑難解答