在 Java 中左移 BigInteger


要在 BigInteger 中左移,請使用 shiftLeft() 方法。

java.math.BigInteger.shiftLeft(int n) 返回一個 BigInteger,其值為 (this << n)。移位距離 n 可能為負值,在這種情況下,此方法會執行右移。它計算 floor(this * 2n)。

示例

 實戰演示

import java.math.*;
public class Demo {
   public static void main(String[] args) {
      BigInteger one;
      one = new BigInteger("25");
      one = one.shiftLeft(3);
      System.out.println("Result: " +one);
   }
}

輸出

Result: 200

更新於:25-6 月-2020

153 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.