search
HomeJavajavaTutorialJAVA shift operator

JAVA shift operator

Dec 16, 2016 pm 05:03 PM

The shift operator is to shift numbers based on binary. According to the direction of translation and the rules of filling numbers, it is divided into three types: > (signed right shift) and >>> (unsigned right shift).
 During the shift operation, the result after the byte, short and char types are shifted will become the int type. When shifting the byte, short, char and int, it is specified that the actual number of moves is the remainder of the number of moves and 32. That is, the result obtained by shifting 33 times and shifting once is the same. When moving a long value, the actual number of moves is the remainder of the number of moves and 64. That is, the result of moving 66 times is the same as moving 2 times.硬 After 386, the hardware of the shift is removed to the word length, and the 32 -bit move to the right is 0 to the right. Shifting right by 32 bits is still 9. You can change the condition of the for loop, for example to i
The movement rules and usage of the three shift operators are as follows:
   Syntax format:
  The number that needs to be shifted   For example: 3   Calculation process:
  3   First Convert 3 to a binary number 0000 0000 0000 0000 0000 0000 0000 0011, then shift out the two zeros in the high bits (left) of the number, shift the other numbers 2 bits to the left, and finally shift the two zeros in the low bits (right) Fill empty spaces with zeros. The final result is 0000 0000 0000 0000 0000 0000 0000 1100, which converted to decimal is 12. Mathematical meaning:
On the premise that the number does not overflow, for positive and negative numbers, shifting one position to the left is equivalent to multiplying by 2 1 to the power of 1, shifting n bits to the left is equivalent to multiplying by 2 to the n power.
  >>Operation rules: Move all numbers to the right according to the corresponding number of digits in binary form, shift out (discard) the low bits, and fill in the sign bits in the high bits, that is, fill in zeros for positive numbers and 1 for negative numbers.
  Grammar format:
 The number that needs to be shifted >> The number of shifts
  For example, 11 >> 2 means shifting the number 11 to the right by 2 places
, and then move out the last two numbers in the low bits. Because the number is a positive number, zeros are padded in the high bits. The final result obtained is 0000 0000 0000 0000 0000 0000 0000 0010. Converted to decimal, it is 3.
Mathematical meaning: shifting one bit to the right is equivalent to dividing by 2, and shifting n bits to the right is equivalent to dividing by 2 to the nth power.
 >>>Operation rules: Move all numbers to the right by the corresponding number of digits in binary form, shift out (discard) the low bits, and fill in the empty bits in the high bits with zeros. The same as signed right shift for positive numbers, but different for negative numbers.
 Other structures are similar to >>.



For more articles related to JAVA shift operators, please pay attention to 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.