28. Converting into a number by an unsigned conversion

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(), Short.toUnsignedInt(), and Short.toUnsignedLong().

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.51.157