Left move operator

Source: Internet
Author: User

int a1 = 12<<1;//24

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

int a3 = 128<<2;//512

int a4 = 129<<2;//516

Discard the binary number at the beginning. Adds a bit 0 to the tail of the binary number.

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

The number a left shift B-bit result is A*2 's B-square

Binary form of 112

1 >12

0000 0000 0000 1100

0000 0000 0001 1000

----------------------equivalent to 10 binary 24

Two

-12 binary

1>12 binary

0000 0000 0000 1100

2> Reverse

1111 1111 1111 0011

3> plus 1

1111 1111 1111 0100

3> left move two bit

1111 1111 1101 0000

4>

into a decimal form

4.1>-1

1111 1111 1100 1111

4.2 > Take Reverse

0000 0000 0011 0000

48

Because it is a negative number, it is-48

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

Three

int a3 = 128<<2;

1>128 binary

0000 0000 1000 0000

2> left two bits in the tail two bits 0

0000 0000 0000 0000

Decimal number is 512

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

0000 0000 1000 0001

129 of the Decimal

Move left two-bit

0000 0010 0000 0100

Decimal is 516

Left move operator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.