int b=a^(1<<index)
a为原整数,index为其中欲取反的位所在索引

解决方案 »

  1.   

    改一下楼上的:
    public class ReverseIntByte {
       public static void main(String[] args) {
       byte a = 25;
       int i = 1;
       int index = 3;
       int b = a^(i<<index);
       System.out.println("test: " + b);
       }
    }
    index是从右往左数的索引。
    比如:a = 25,取右边起第3位反。
    那么a = 11001
    b = a^(1000) = 11001^1000 = 10001 = 17