Search code examples
javac#parsinglong-integertypeconverter

Convert.ToInt64 equivalent in java


I try the following code in c# and it give me the result as follow:

long dec1 = Convert.ToInt64("B62FD56EFD5B375D", 16);

result : -531879796222753398

I am trying to do this in java, but I always get NumberFormatException, because there are alphanumeric inside the String. What I code in java is:

Long.parseLong("B62FD56EFD5B375D", 16);

May I know what is the equivalent of this in java?


Solution

  • You can use Long.parseUnsignedLong in Java to get the same result.

    long result = Long.parseUnsignedLong("B62FD56EFD5B375D", 16);