C ++ allows you to combine two integer comparisons in one to test a range, e.g.
(unsigned)X < (unsigned)Upper
which returns true when
0 <= X < Upper
The Java language does not have an unsigned type. Do you see a way to get the same effect using one comparison and not too much overhead?
Update
From a comment by @Bathsheba, the char type is not 16 bit and would be suitable for my purpose, since my integers are really in the short range.
The question remains open for simple int s.
Perhaps something in the string (X | (Upper - 1 - X)) >= 0 , which allows a range of 30 bits.
java comparison
Yves daoust
source share