在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
廣告