Lilou Laure wrote:. . . the integer is interpreted as a signed number, its not happening correctly. . . . .
That is correct. It is the
String input that has to be unsigned. Just because there is a method for parsing Strings as unsigned, that doesn't mean there has been a change in the structure of the
primitive int datatype, which is as always two's complement. Have you read the details of the
Integer#parseUnsignedInt() method? It returns an ordinary
int. Maybe Java® is wrong not to have unsigned numbers, but it doesn't.
Link explaining why unsigned numbers might be unhelpful. So the unsigned method doesn't accept negative arguments.
Campbell's Computer wrote:java UnsignedIntDemo 0 +0 1 +1 1234567890 2222222222 -1234567890
0
0
1
1
1234567890
-2072745074
Exception in thread "main" java.lang.NumberFormatException: Illegal leading minus sign on unsigned string -1234567890.
at java.base/java.lang.Integer.parseUnsignedInt(Integer.java:827)
at java.base/java.lang.Integer.parseUnsignedInt(Integer.java:928)
at UnsignedIntDemo.main(UnsignedIntDemo.java:7)
Notice that 2222222222 is interpreted in two's complement. If you tried
Integer.parseInt("2222222222") you would suffer a number format exception.
So, ~1 has always been −2 and it still is −2.