&,|,^的用法

&,|,~,^的用法

  • &按位与
  • |按位或
  • ~按位非
  • ^按位异或

举例: int x = 5; int y = 11;

System.out.println(x|y); System.out.println(x&y); System.out.println(x~y); System.out.println(x^y);

结果是15, 1 ,14

分析:

x=5 (0101二进制)

y=11(1011二进制)

x&y = 0001 = 1

x|y = 1111 = 15

~x = 1010 = 10

x^y = 1110 = 14


^的运用与性质

原文地址:https://www.cnblogs.com/lijingran/p/8854986.html