I have written an interpreter that requires me to perform 32-bit division of unsigned integers. In Java, I can do this as:
reg[a] = (int) ((reg[b] & 0xFFFFFFFFL) / (reg[c] & 0xFFFFFFFFL));
But I would like to avoid the conversion to long and back to int. Java already gives the unsigned right shift operator >>>
for that special case, so maybe there is a clever way to do unsigned division in the same way.
Note that add and multiply work fine, since two's compliment numbers just work.
Is there a better way in Java to do this?