在Java中右移BigInteger


要在BigInteger中右移,使用shiftRight()方法。

java.math.BigInteger.shiftRight(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.shiftRight(3);
      System.out.println("Result: " +one);
   }
}

輸出

Result: 3

更新於: 2020年6月29日

161次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始學習
廣告