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