Is there an easy and fast way to convert a Java signed long to an unsigned long string?
-1 -> "18446744073709551615"
-9223372036854775808 -> "09223372036854775808"
9223372036854775807 -> "09223372036854775807"
0 -> "00000000000000000000"
Here is a solution using BigInteger:
This works since the unsigned value of a (signed) number in two-s complement is just 2(number of bits) more than the signed value, and Java’s
longhas 64 bits.And BigInteger has this nice
toString()method which we can use here.