There are methods Integer.toHexString()
and Long.toHexString()
. For some reason they didn\'t implement Short.toHexString()
.
What
You can convert your Integer.toHexString
in to a hex string for short value.
Integer
is of 32 bit
, and Short
is of 16 bit
. So, you can just remove the 16 most significant bit from Hex String
for short value
converted to integer
, to get a Hex String
for Short
.
Integer -> -33 = 11111111 11111111 11111111 11011111 == Hex = ffffffdf
Short -> -33 = 11111111 11011111 == Hex = ffdf
So, just take the last 4
characters of Hex String
to get what you want.
So, what you want is: -
Short sh = -33;
String intHexString = Integer.toHexString(sh.intValue());
String shortHexString = intHexString.substring(4);
I think that would work.