Java 程序,翻转 BigInteger 中的一个二进制位
要在 Java 中翻转 BigInteger 中的一个二进制位,可使用 flipBit() 方法。该方法返回一个 BigInteger,其值等同于此 BigInteger,但指定二进制位已被翻转。
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger one, two;
one = new BigInteger("7");
one = one.flipBit(3);
System.out.println("Result: " +one);
}
}输出
Result: 15
让我们看另一个示例。
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger bi1, bi2;
bi1 = new BigInteger("8");
bi2 = bi1.flipBit(1);
String str = "Flipbit operation on " +bi1+ " at index 1 gives " +bi2;
System.out.println( str );
}
}输出
Flipbit operation on 8 at index 1 gives 10
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP