0

As we know a Max of long is 9223372036854775807

in my case I want to convert this number dec = 11265437495266153437 to hex using this method Integer.toHexString(dec)

any idea to how get this reasult res = 9C56DFB710B493DD !

Mojackoo
  • 83
  • 2
  • 11

1 Answers1

3

BigInteger::toString( radix )

Call BigInteger::toString and pass 16 to get hexadecimal text.

Do it as follows:

import java.math.BigInteger;

public class Main {
    public static void main(String[] args) {
        String value = 
                new BigInteger("11265437495266153437", 10)
                .toString(16)
                .toUpperCase()
        ;
        System.out.println(value);
    }
}

Output:

9C56DFB710B493DD

Note that the default radix is 10 so you can skip it and use new BigInteger("11265437495266153437") instead which is without any radix parameter.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110