You can always negate if it's negative.
private void test(String[] args) {
test(BigInteger.ONE.shiftLeft(10));
test(BigInteger.valueOf(-50));
}
private void test(BigInteger bigInteger) {
test1(bigInteger);
test1(bigInteger.negate());
}
private void test1(BigInteger bi) {
System.out.println(bi.toString(2)+" >> 5 = "+bi.shiftRight(5).toString(2));
}
NB: Remember that BigInteger
is immutable so if you do maths on them you must keep the returned result because the maths does not modify the value, it returns the calculated result.