Performing Bitwise Operations with BigInteger in Java
Description
The following code shows how to performing Bitwise Operations with BigInteger.
Example
//w ww . ja v a 2s. co m
import java.math.BigInteger;
public class Main {
public static void main(String[] argv) throws Exception {
byte[] bytes = new byte[] { 0x1, 0x00, 0x00 };
BigInteger bi = new BigInteger(bytes);
System.out.println(bi);
boolean b = bi.testBit(3);
System.out.println(b);
b = bi.testBit(16);
System.out.println(b);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »