I have a large number. I need to grab the number represented by the first 21 bits. I do this by doing:
(number & 0xFFFFF8000L) >>> 15;
I can do this:
var origEncodedVal = 26766802693;
var encodedVal = new BigInteger(""+origEncodedV
var mask = new BigInteger("FFFFF8000",16)
var result = encodedVal.and(mask).shift
but won't the final result be wrong if the initial bit is set in the original encoded value? I'm not worried about other masks on that number like 0x000007F00 because the high bit will be 0 regardless, so a signed shift and unsigned shift do the same thing in that case..
How do I deal with this? Why does BigInteger not implement unsigned shift right? The javadoc of BigInteger 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."
but that statement doesn't make any sense to me.
I suppose one solution would be to shift right one bit and then AND it with a mask that zeroes out the high bit. Is that my best bet or is there a better way to do it? Another solution I suppose would be to prefix the original number with "0" and adjust the masks accordingly. It just seems silly that I would need to do that though.