September 2019
Intermediate to advanced
816 pages
18h 47m
English
The problem requires that we convert the given signed int into long via an unsigned conversion. So, let's consider signed Integer.MIN_VALUE, which is -2,147,483,648.
In JDK 8, by using the Integer.toUnsignedLong() method, the conversion will be as follows (the result will be 2,147,483,648):
long result = Integer.toUnsignedLong(Integer.MIN_VALUE);
Here is another example that converts the signed Short.MIN_VALUE and Short.MAX_VALUE into unsigned integers:
int result1 = Short.toUnsignedInt(Short.MIN_VALUE);int result2 = Short.toUnsignedInt(Short.MAX_VALUE);
Other methods from the same category are Integer.toUnsignedString(), Long.toUnsignedString(), Byte.toUnsignedInt(), Byte.toUnsignedLong() ...