public class test{
and operators are represented by the symbol "&"
Only two digits are 1, the result is 1, you can know the result is 1, that is 1
public static void Main (string[] args) {
int a = 1;
int b = 129;
System.out.println (A + "tobinary:" + integer.tobinarystring (a));
System.out.println (b + "tobinary:" + integer.tobinarystring (b));
System.out.println (A + "&" + B + "=" + (A & B));
}
}
Output:
1 tobinary:1
129 tobinary:10000001
1 & 129 = 1
public class test{
Or operator with the symbol "|" Said
Two bit as long as there is a 1, then the result is 1, or 0, you can know the result is 10000001, that is 129
public static void Main (string[] args) {
int a = 1;
int b = 129;
System.out.println (A + "tobinary:" + integer.tobinarystring (a));
System.out.println (b + "tobinary:" + integer.tobinarystring (b));
System.out.println (A + "|" + b + "=" + (a) | b));
}
}
Output:
1 tobinary:1
129 tobinary:10000001
1 | 129 = 129
public class test{
Or operator is represented by the symbol "~"
public static void Main (string[] args) {
int b = 129;
System.out.println (b + "tobinary:" + integer.tobinarystring (b));
System.out.println (~B);
}
}
Output:
129 tobinary:10000001
-130
public class test{
Or operator is represented by the symbol "^"
Two operands in the same bit, the result is 0, the result is 1, you can know the result is 10000000, that is 128
public static void Main (string[] args) {
int a = 1;
int b = 129;
System.out.println (A + "tobinary:" + integer.tobinarystring (a));
System.out.println (b + "tobinary:" + integer.tobinarystring (b));
System.out.println (A + "^" + B + "=" + (a ^ b));
}
}
Output:
1 tobinary:1
129 tobinary:10000001
1 ^ 129 = 128