左移動操作符

來源:互聯網
上載者:User

標籤:

int a1 = 12<<1;//24

int a2 = -12<<2;//-48

int a3 = 128<<2;//512

int a4 = 129<<2;//516

捨棄位元開頭一位.在位元尾部增加一位0.

a*2^b<===a<<b

數字a左移b位結果為 a*2的b次方

 

一 12的二進位形式

1 >12

0000 0000 0000 1100

0000 0000 0001 1000

----------------------等價於10進位24

-12的二進位

1>12二進位

0000 0000 0000 1100

2>取反

1111 1111 1111 0011

3>加1

1111 1111 1111 0100

3>左移動兩位

1111 1111 1101 0000

4>

變為十進位的形式

4.1>-1

1111 1111 1100 1111

4.2 >取反

0000 0000 0011 0000

48

由於是負數故為-48

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

int a3 = 128<<2;

1>128二進位

0000 0000 1000 0000

2>左移動兩位 在尾部補兩位0

0000 0000 0000 0000

十進位數為512

四  int a4 = 129<<2;//516

0000 0000 1000 0001

129的十進位

左移兩位

0000 0010 0000 0100

十進位為516

 

左移動操作符

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.