改一下楼上的: 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
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