Search code examples
javastringhexshort

String to Hex Short java


I have a variable define as

short s1 = 0x3039;

to do some operation, converting it to string

String ss = Integer.toHexString(s1 & 0xffff);

which give result as string "3039". After some string operation it is converted to string "3130". Now i want it back as

short s2 = 0x3130;

How can this be achieved ?


Solution

  • You can use Short.parseShort with 16 as radix

    Short.parseShort(yourHexString, 16)