Java BigInteger shiftRight() 方法

2025 年 3 月 20 日 | 阅读 2 分钟

Java BigInteger 类的 shiftRight() 方法用于将位向右移动 n 次(移位距离)。此方法返回一个 BigInteger,其值为 (this >> n)。此方法计算 floor (this / 2^n)。

语法

参数

n - 移位距离,以位为单位。

返回值

此方法返回 (this >> n)。

Exception

不适用

注意:移位距离 n 可能是负数,在这种情况下,此方法执行左移。

示例 1

输出

Shift Right operation on 5, 2 times gives 1

示例 2

输出

Shift Right operation on 5, -2 times gives 20

示例 3

输出

Shift Right operation on 1, 4 times gives 0
 
下一主题Java BigInteger