目录

static int rotateLeft(int i, int distance)

描述 (Description)

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

声明 (Declaration)

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

public static int rotateLeft(int i, int distance)

参数 (Parameters)

  • i - 这是int值。

  • distance - 这是旋转距离。

返回值 (Return Value)

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

异常 (Exception)

NA

例子 (Example)

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

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

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

32
512
8192
131072
↑回到顶部↑
WIKI教程 @2018