#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; //分别向左右移一位再异或,即可得到相邻两位异或的结果 temp1 <<= 1; //左移一位在加上溢出的 temp2 >>= 31; num1 = temp1 + temp2; temp3 = num; temp4 = num; temp3 >>= 1; //右移一位在加上舍弃的 temp4 <<= 31; num2 = temp3 + temp4; num = num1 ^ num2; //相邻两位异或 printf("%ud",num);}
新闻热点
疑难解答