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)); } }
Running results:
1010 10100 1010
Let’s align the above results:
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!