Home > Java > javaTutorial > body text

What does Java << mean?

青灯夜游
Release: 2019-11-15 17:43:15
Original
5826 people have browsed it

What does Java << mean?

Java <

<< is a bitwise left shift operator, which means logical left shift, padding 0 on the right, and the sign bit needs to be moved like other bits.

Mathematical meaning: As long as the number does not overflow, for positive and negative numbers, shifting one position to the left is equivalent to multiplying by 2 raised to the power of 1, and shifting n bits to the left is equivalent to multiplying n by 2. second power.

Calculation: 3 << 2

##3 << 2, then shift the number 3 to the left by 2 places

1, First convert 3 into a binary number 0000 0000 0000 0000 0000 0000 0000 0011

2, then move out the two zeros in the high bits (left side) of the number, and shift the other numbers 2 bits to the left, and finally in The two empty bits in the lower (right) bits are filled with zeros.

3. The final result is 0000 0000 0000 0000 0000 0000 0000 1100, which is 12 when converted to decimal.

Assignment operators supported by Java language

=: Simple assignment operator, assigns the value of the right operand to the left operation number. For example, C = A B will assign the value obtained by A B to C.

=: Addition assignment operator, which adds the left operand and the right operand and assigns them to the left operand. For example, C = A is equivalent to C = C A.

- =: Subtraction and assignment operator, which subtracts the left operand and the right operand and assigns them to the left operand. For example, C - = A is equivalent to C = C -A.

* =: Multiplication and assignment operator, which multiplies the left operand and the right operand and assigns them to the left operand. For example, C * = A is equivalent to C = C * A.

/ =: Division and assignment operator, which divides the left operand and the right operand and assigns the value to the left operand. For example, C / = A is equivalent to C = C / A.

(%)=: Modulo and assignment operator, which modulo the left and right operands and assigns the value to the left operand. For example, C%=A is equivalent to C=C%A.

<< =: left shift assignment operator. For example, C << = 2 is equivalent to C = C << 2.

>> =: Right shift assignment operator. For example, C >> = 2 is equivalent to C = C >> 2.

&=: Bitwise AND assignment operator. For example, C&=2 is equivalent to C=C&2.

^ =: Bitwise XOR assignment operator. For example, C^=2 is equivalent to C=C^2.

| =: Bitwise OR assignment operator. For example, C | = 2 is equivalent to C = C | 2.

The above is the detailed content of What does Java << mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!