Home  >  Article  >  Java  >  What does Java's >> mean?

What does Java's >> mean?

(*-*)浩
(*-*)浩Original
2019-11-14 10:29:374120browse


What does Java's >> mean?

Shift operator

The operand of the shift operator is also a binary "bit ". They can be used alone to handle integer types (one of the main types). (Recommended learning: java course)

>> is a right shift operator, which moves the operand on the left side of the operator to the right by the number of digits specified on the right side of the operator. .

Its general format is as follows:

value >> num

num specifies the number of bits to shift the value value.

Just remember one thing about the right shift rule: the sign bit remains unchanged, and the sign bit is added on the left.

Operation rules:

According to binary form All numbers are shifted to the right by the corresponding number of digits, the low bits are shifted out (discarded), and the high bits are filled with sign bits, that is, zeros are filled for positive numbers and 1 for negative numbers.

When the operands of the right shift are byte and short types , these types will be automatically expanded to int type.

For example, if the value to be removed is a negative number, each right shift adds 1 to the left. If the value to be removed is a positive number, each right shift adds 0 to the left. This is called a sign. Bit extension (retained sign bit) (sign extension) is used to maintain the sign of negative numbers when performing a right shift

operation.

Calculation process

11 >>2 (11 is int type)

1) The binary form of 11 is: 0000 0000 0000 0000 0000 0000 0000 1011

2) Move out the last two numbers in the low bits. Because the number is a positive number, zeros are added to the high bits.

3) The final result is 0000 0000 0000 0000 0000 0000 0000 0010.

Converted to decimal is 3.

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

Statement:
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
Previous article:How to delete in java?Next article:How to delete in java?