BigInteger bit shift left and right
In this chapter you will learn:
Left shift bit value on BigInteger
BigInteger shiftLeft(int n)
Returns a BigInteger whose value is (this << n).
import java.math.BigInteger;
/* j a va 2s.c om*/
public class Main {
public static void main(String[] argv) throws Exception {
byte[] bytes = new byte[] { 0x1, 0x00, 0x00 };
BigInteger bi = new BigInteger(bytes);
bi = bi.shiftLeft(3);
System.out.println(bi);
}
}
The output:
Right shift bit on BigInteger
BigInteger shiftRight(int n)
returns a BigInteger whose value is (this >> n).
import java.math.BigInteger;
// j a va 2s.co m
public class Main {
public static void main(String[] argv) throws Exception {
byte[] bytes = new byte[] { 0x1, 0x00, 0x00 };
BigInteger bi = new BigInteger(bytes);
bi = bi.shiftRight(1);
System.out.println(bi);
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » BigDecimal BigInteger