java的基礎知識運算子

來源:互聯網
上載者:User

標籤:system   作用   line   邏輯運算   print   規律   關係運算   移位   運算子   

一.運算子。1.算數運算子:+,-,*,/,%2.自增自減 :++ ,--

++在前 先運算在賦值

++在後 先賦值後運算

-- 減減同上.

3.賦值運算子 : = ,+=,-=,*=,/=4.關係運算子 : >,<,>=,<=,== ,!=5.邏輯運算子: & ,| ,! ,&& ,||6.位元運算符:(1).位元運算符的符號:

& (與):兩者都是1的時候我就是一,其他都是0

|(或):兩者都為0時才為0 ,其他的都是1.

^(異或):兩者不同為1,相同為0

~(取反):0變為1,1變為0.

(2).負數的表現形式: 二進位位的最高位為1,那麼這個數就是一個負數。

-1:1111-1111  1111-1111 1111-1111 1111-1111

 0:0000-0000 0000-0000 0000-0000 0000-0000

-2:1111-1111  1111-1111 1111-1111 1111-1110

-3:1111-1111  1111-1111 1111-1111 1111-1101

-4:1111-1111  1111-1111 1111-1111 1111-1100

-5:1111-1111  1111-1111 1111-1111 1111-1011

-6:1111-1111  1111-1111 1111-1111 1111-1010

-7:1111-1111  1111-1111 1111-1111 1111-1001

 7:0000-0000  0000-0000 0000-0000 0000-0111

規律:負數所對應的正數-1 ,取反負數所對應的正數取反+1

(3).移位操作符:對二進位位進行操作

 >>  右移

<<  左移

>>> 無符號右移

//右移:

           System.out.println(6>>1); // --->3  6/2  2*1

           System.out.println(6>>2); // --->1  6/4  2*2

           System.out.println(6>>3); // --->0  6/8  2*3

           System.out.println(-6>>1); //  -6/2 -->-3 

//規律: 右移多少位,就用需要移動的數除以2的多少次方。//左移 :

           System.out.println(6<<1); // --->12  6*2  2*1

           System.out.println(6<<2); // --->24  6*4  2*2

           System.out.println(6<<3); // --->48  6*8  2*2*2

           System.out.println(6<<4); //---->96  6*16 2*2*2*2

           System.out.println(-6<<2);//--->-24

//規律: 左移多少位,就用這個數乘以2多少次方。//>>>無符號的右移特點:無論你的最高位是0還是1,空缺位都補0。

           System.out.println(6>>>1); //3

           System.out.println(6>>>2); //1

           System.out.println(-6>>>2); // 1073741822

作用 : 提高運算速率。位元運算是執行最快。特點 : 一個數A和兩個相同的數^,最後結果還是原來的數A。

java的基礎知識運算子

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.