Java BigInteger flipBit() 方法

2025年3月20日 | 阅读时长1分钟

Java BigInteger 类的 flipBit() 方法用于翻转 BigInteger 中的特定位。此方法返回翻转了索引 n 处的位后的 BigInteger。

语法

参数

n - 要翻转的位的索引

返回值

此方法返回一个 BigInteger 对象,其值为 this ^ (1<< n)。

抛出

ArithmeticException? 如果 n 为负数。

示例 1

输出

FlipBit operation on 5 at index 1 gives  7

示例 2

输出

java.lang.ArithmeticException: Negative bit address
 
下一主题Java BigInteger