Home > Java > Javagetting Started > What is '>>' in java

What is '>>' in java

王林
Release: 2019-11-22 15:28:21
Original
10845 people have browsed it

What is '>>' in java

There are three shift operators in java

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

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

package com.b510.test;
public class Test {
    public static void main(String[] args) {
        int number = 10;
        //原始数二进制
        printInfo(number);
        number = number << 1;
        //左移一位
        printInfo(number);
        number = number >> 1;
        //右移一位
        printInfo(number);
    }
    private static void printInfo(int num){
        System.out.println(Integer.toBinaryString(num));
    }
}
Copy after login

Running results:

1010
10100
1010
Copy after login

Let’s align the above results:

What is >> in java

Recommended tutorial: java Quick Start

The above is the detailed content of What is '>>' in java. 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