这个 JAVA数学大整数。希夫特利夫特(国际北) 方法返回一个BigInteger,其值为(this<
null
语法:
public BigInteger shiftLeft(int n)
参数: 该方法采用一个参数 N 整数类型,指移位距离,以位为单位。
返回值: 该方法在将位向左移位n次后返回BigInteger。
例外情况: 该方法可能会引发 算术异常 如果移位距离为整数。最小值。
例如:
Input: value = 2300, shift distance = 3 Output: 18400 Explanation: Binary Representation of 2300 = 100011111100 shift distance = 3 after shifting 100011111100 left 3 times then Binary Representation becomes 100011111100000 and Decimal equivalent of 100011111100000 is 18400. Another way of expressing the same can be 2300*(2^3)=18400 Input: value = 35000, index = 5 Output: 1120000
下面的程序演示了BigInteger的shiftLeft(索引)方法。
// Program to demonstrate shiftLeft() method of BigInteger import java.math.*; public class GFG { public static void main(String[] args) { // Creating BigInteger object BigInteger biginteger = new BigInteger( "2300" ); // Creating a int i for Shift Distance int i = 3 ; // Call shiftLeft() method on bigInteger at index i // store the return value as BigInteger BigInteger changedvalue = biginteger.shiftLeft(i); String result = "After applying ShiftLeft by Shift Distance " + i + " on " + biginteger + " New Value is " + changedvalue; // Printing result System.out.println(result); } } |
输出:
After applying ShiftLeft by Shift Distance 3 on 2300 New Value is 18400
参考: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#shiftLeft(国际)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END