I wrote an interpreter that requires me to perform 32-bit division of unsigned integers. In Java, I can do it like:
reg[a] = (int) ((reg[b] & 0xFFFFFFFFL) / (reg[c] & 0xFFFFFFFFL));
But I would like to avoid converting to long and back to int. Java already provides an unsigned right shift operator >>> for this special case, so there may be a smart way to do unsigned division in the same way.
Please note that adding and multiplying work fine, as only two compliment numbers work.
Is there a better way in Java to do this?
source share