search
HomeJavaJavagetting StartedWhat does Java's >> mean?

What does Java's >> mean?

Nov 14, 2019 am 10:29 AM
java


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.