java.math.BigInteger.shiftLeft(int n)%uA0返回一个BigInteger,其值为(this<< n)。移位距离,在这种情况下,正也可能为负,这个方法执行右移。它计算 floor(this * 2n).
声明
以下是java.math.BigInteger.shiftLeft()方法的声明
public BigInteger shiftLeft(int n)
参数
-
n%uA0- 移动距离,以位
返回值
该方法返回一个BigInteger对象的值是 this << n .
异常
-
ArithmeticException%uA0- 如果移位距离为Integer.MIN_VALUE
例子
下面的例子显示math.BigInteger.shiftLeft()方法的用法
package com.yiibai import java.math.* public class BigIntegerDemo { public static void main(String[] args) { // create 3 BigInteger objects BigInteger bi1, bi2, bi3 bi1 = new BigInteger("10") // perform leftshift operation on bi1 using 2 and -2 bi2 = bi1.shiftLeft(2) bi3 = bi1.shiftLeft(-2) String str1 = "Leftshift on " + bi1 + ", 2 times gives " +bi2 String str2 = "Leftshift on " + bi1 + ",-2 times gives " +bi3 // print bi2, bi3 values System.out.println( str1 ) System.out.println( str2 ) } }
让我们编译和运行上面的程序,这将产生以下结果:
Leftshift on 10, 2 times gives 40 Leftshift on 10,-2 times gives 2