即把10000000-》00000001 10000010-》01000001 int FlipBits(int k,int bits)//k为要反转的对象,bits为对象拥有的位数 { int lm = 1 << (bits-1); int rm = 1; int r = 0; while(rm != 0){ if((k & rm) != 0) r += lm; lm >>= 1; rm <<= 1; } retrun r; }