1. 程式人生 > >運算子號

運算子號

基本型別:byte,short,int,long,float,double,char,boolean

操作符號:+ 任意的資料,都可以與String相加,相加的結果都是字串串聯。

                   ++:自增

                   - - :自減

關於宣告int型別:

0b :二進位制

                 0 :8進位制

                0x:16進位制

                00:十進位制

    

public void Demo{
public static void main(String[] args) {
		int a = 0b1111;
		int b = 017;
		int c = 15;
		int d = 0xf;
		System.err.println(a);
		System.err.println(b);
		System.err.println(c);
		System.err.println(d);
     }
}


運算子號:

+=

例:a+=3;=> a=a+3;

位運算子號:

    int型別在記憶體中佔4個位元組,8位。

>> :右位移

00000000_00000000_00000000_00000100       -2    右移一位數規則是原來的數字除以2;

>>

1

-----------------------------------------------

00000000_00000000_00000000_ 00000001       1


int a=0b1111;  rwx  111   -7   777
//右移兩位數,1111是15,右移兩位是11十進位制是3
//又因為是int型別所以15\3=4,所以右移兩位數的規 //則是原來的數字除以四
int b=a>>2;
System.err.println(b);  // 3




<< 左
       int a=0b0010;
       int b=a<<1;
       System.err.prinln(b);


>>> 無符號右
       int c=a>>>1;
       System.err.println(c+"," +Integer.toBinaryString(c)); //正數



| 或  兩個只要一個為1,就是1
  
int a =0b1010;
int b =0b0101;
int c=a | b; //1111
System.err.println(c+","+Integer.toBinaryString(c));



&: 與   兩個必須都是1
                int a = 0b1010;
		int b = 0b0101;
		int c = a & b;//0000
		System.err.println(c+","+Integer.toBinaryString(c));




~ :按位取反
   	        int a = 0b1010;
		int b = ~a;//
		System.err.println(b+","+Integer.toBinaryString(b));




^ 異或        1 ^ 0 = 1  
	        int a = 0b1010;
		int b = 0b1111;
		int c = a^b;//0101
		System.err.println(c);