Home Java javaTutorial Shift operators in java: ,>>> summary

Shift operators in java: ,>>> summary

Dec 16, 2016 pm 04:57 PM

There are three shift operators in java

<< : : Left shift operator, num << 1, which is equivalent to multiplying num by 2

>> : : Right shift operator, num >> ; 1, which is equivalent to dividing num by 2

>>> : Unsigned right shift, ignore the sign bit, and fill the gaps with 0

Let’s take a look at how these shift operations are used

/**
 * 
 */
package com.b510.test;

/**
 * @author Jone Hongten
 * @create date:2013-11-2
 * @version 1.0
 */
public class Test {

    public static void main(String[] args) {
        int number = 10;
        //原始数二进制
        printInfo(number);
        number = number << 1;
        //左移一位
        printInfo(number);
        number = number >> 1;
        //右移一位
        printInfo(number);
    }
    
    /**
     * 输出一个int的二进制数
     * @param num
     */
    private static void printInfo(int num){
        System.out.println(Integer.toBinaryString(num));
    }
}
Copy after login

The running result is:

1010
10100
1010
Copy after login

Let’s align the above results:

位数
--------
     十进制:10     原始数         number
     十进制:20     左移一位       number = number << 1;
     十进制:10     右移一位       number = number >> 1;
Copy after login

After reading the above demo, do you now know a lot about left shift and right shift?

For: >>>

Unsigned right shift, ignore the sign bit, and fill the gaps with 0

value >>> num -- num specifies the number of digits to shift the value value.

Just remember one thing about the rules of unsigned right shift: ignore the sign bit extension and fill the highest bit with 0. The unsigned right shift operator>>> is only meaningful for 32-bit and 64-bit values ​​


More shift operators in java: <<,>>,>>> To summarize related articles, please pay attention to the PHP Chinese website!

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

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 Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)