I'm trying to apply an unsigned shift on the right but I cannot find the way to do it. Is there anyone who knows?
Sample code:
BigInteger bi;
bi.shiftRight(7) // equals >> 7
How to apply >>> 7 ?
Duplicate? Please stahp, I don't have my answer.
I'm trying to apply an unsigned shift on the right but I cannot find the way to do it. Is there anyone who knows?
Sample code:
BigInteger bi;
bi.shiftRight(7) // equals >> 7
How to apply >>> 7 ?
Duplicate? Please stahp, I don't have my answer.
As the BigInteger javadocs says:
The unsigned right shift operator (>>>) is omitted, as this operation makes little sense in combination with the "infinite word size" abstraction provided by this class.
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.
I would advise perhaps using a type of unsigned int int in order to allow for the use of operators as you wish to use and insure data is only unsigned.