目录

static int rotateRight(int i, int distance)

描述 (Description)

java.lang.Integer.rotateRight()方法返回通过将指定的int值的二进制补码二进制表示向右旋转指定的位数而获得的值。 (位移出右手,或低位,侧面重新进入左侧,或高位。)

声明 (Declaration)

以下是java.lang.Integer.rotateRight()方法的声明

public static int rotateRight(int i, int distance)

参数 (Parameters)

  • i - 这是int值。

  • distance - 这是旋转距离。

返回值 (Return Value)

此方法返回通过将指定的int值的二进制补码表示法向右旋转指定的位数而获得的值。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.lang.Integer.rotateRight()方法的用法。

package com.iowiki;
import java.lang.*;
public class IntegerDemo {
   public static void main(String[] args) {
      int n = 2;
      // returns the value obtained by rotating right
      for(int i = 0; i < 4; i++) {
         n = Integer.rotateRight(n, 4);
         System.out.println(n);
      }
   }
} 

让我们编译并运行上面的程序,这将产生以下结果 -

536870912
33554432
2097152
131072
↑回到顶部↑
WIKI教程 @2018