javaencodinghexdecodingbase36

Java convert String text to base36 and from base36 to hex


Is there any api in java to convert simple string to base36/base10 and from base36/base10 to hex representation.

example: input: '-22EEVX' encoding base36 output: f8 8d 33 23


Solution

  • Use Integer class and radix parameter of parseInt, and toHexString from the same class.

    Integer.toHexString(Integer.parseInt("-22EEVX", 36));
    

    For base10 it is even shorter (you omit radix parameter, it is assumed 10):

    Integer.toHexString(Integer.parseInt("-22"));