知识点:
按位操作符用来操作整数基本数据类型的单个比特,即二进制位
package tv.zhangjia.one; public class Test10 { public static void main(String[] args) { int i1 = 0xaaaaaaaa; int i2 = 0x55555555; System.out.println("i1 = " + Integer.toBinaryString(i1)); System.out.println("i2 = " + Integer.toBinaryString(i2)); System.out.println("~i1 = " + Integer.toBinaryString(~i1)); System.out.println("~i2 = " + Integer.toBinaryString(~i2)); System.out.println("i1 & i1 = " + Integer.toBinaryString(i1 & i1)); System.out.println("i1 | i1 = " + Integer.toBinaryString(i1 | i1)); System.out.println("i1 ^ i1 = " + Integer.toBinaryString(i1 ^ i1)); System.out.println("i1 & i2 = " + Integer.toBinaryString(i1 & i2)); System.out.println("i1 | i2 = " + Integer.toBinaryString(i1 | i2)); System.out.println("i1 ^ i2 = " + Integer.toBinaryString(i1 ^ i2)); } } 输出: i1 = 10101010101010101010101010101010 i2 = 1010101010101010101010101010101 ~i1 = 1010101010101010101010101010101 ~i2 = 10101010101010101010101010101010 i1 & i1 = 10101010101010101010101010101010 i1 | i1 = 10101010101010101010101010101010 i1 ^ i1 = 0 i1 & i2 = 0 i1 | i2 = 11111111111111111111111111111111 i1 ^ i2 = 11111111111111111111111111111111
请注意,Integer.toBinaryString()不会打印前导零
请登录之后再进行评论