按位與&: 只要對應的二個二進位都為1時,結果位就為1 按位或|:只要對應的二個二進位有一個為1時,結果位就為1 按位異或^:0⊕0=0,1⊕0=1,0⊕1=1,1⊕1=0(同為0,異為1) 按位非:取反操作符 ...
按位與&: 只要對應的二個二進位都為1時,結果位就為1
按位或|:只要對應的二個二進位有一個為1時,結果位就為1
按位異或^:0⊕0=0,1⊕0=1,0⊕1=1,1⊕1=0(同為0,異為1)
按位非:取反操作符
//: object/Bit.java package object; import static net.util.Print.*; public class Bit{ public static void main(String[] args){ int n1=3; int n2=4; print("n1 = " + Integer.toBinaryString(n1)); print("n2 = " + Integer.toBinaryString(n2)); print("n1&n2 = " + Integer.toBinaryString(n1&n2));//按位與 print("n1|n2 = " + Integer.toBinaryString(n1|n2));//按位或 print("n1^n2 = " + Integer.toBinaryString(n1^n2));//按位異或 print("~n2 = " + Integer.toBinaryString(~n2));//按位非 } }/* output: n1 = 11 n2 = 100 n1&n2 = 0 n1|n2 = 111 n1^n2 = 111 ~n2 = 11111111111111111111111111111011 *///~