Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Signed Int to Unsigned String value in Java

To keep this short, I am getting a signed number, -25771 (in Java), that I need the unsigned String representation of, which is "4294941525". Java thinks the number is signed two's complement, but I need its unsigned value.

I noticed the Javadoc for the toString() method for Integers only converts to signed representation.

Is there not a bitwise operation such as "& 0xFF" that I can do to get the unsigned number?

like image 298
Alex W Avatar asked May 17 '26 07:05

Alex W


1 Answers

In Java 8, you can just use Integer.toUnsignedString(int i).

like image 130
Hans Brende Avatar answered May 19 '26 19:05

Hans Brende