Java BigInteger shiftLeft() 方法

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

Java BigInteger 类的 shiftLeft() 方法用于将该 BigInteger 的二进制位向左移动 n 次(移位距离)。此方法返回一个 BigInteger,其值为 (this<<n)。此方法计算 floor (this * 2n)。

语法

参数

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

返回值

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

Exception

不适用

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

示例 1

输出

Shift left operation on 5, 2 times gives 20

示例 2

输出

Shift left operation on 5, -2 times gives 1

示例 3

输出

Shift left operation on 1, 4 times gives 16
 
下一主题Java BigInteger