心情郁闷,上论坛混混日子,写来耍耍吧。:)
#include <stdio.h>
int main(void){
unsigned long
flag[32] = {0x1,0x2,0x4,0x8,
0x10,0x20,0x40,0x80,
0x100,0x200,0x400,0x800,
0x1000,0x2000,0x4000,0x8000,
0x10000,0x20000,0x40000,0x80000,
0x100000,0x200000,0x400000,0x800000,
0x1000000,0x2000000,0x4000000,0x8000000,
0x10000000,0x20000000,0x40000000,0x80000000};
int i;
unsigned long
x;
unsigned long
temp1;
unsigned long
temp2;
printf("请输入一个整数(十进制):");
scanf("%ld", &x);
for(i = 0; i < 16; i++){
temp1 = x & flag[i];
temp2 = x & flag[31 - i];
if(temp1 == flag[i]){
if(temp2 != flag[31 -i]){
x = x^flag[i];
x = x|flag[31 - i];
}
}
else{
if(temp2 == flag[31 -i]){
x = x|flag[i];
x = x^flag[31 - i];
}
}
}
printf("DWORD倒置的结果为:%ld", x);
return 0;
}