Search code examples
javainthexshort

Signed int to 16 bit hex string in Java


I use this code

short s = (short) Integer.parseInt("3321",16);

to convert from 3321 to 13089

How can I make the inverse and convert from 13089 to 3321 ?


Solution

  • Integer provides a method for this.

    String out = Integer.toHexString(13089);
    

    out will have the value "3321".