There are methods Integer.toHexString()
and Long.toHexString()
. For some reason they didn\'t implement Short.toHexString()
.
What
Not the simplest way to do this, but I you can get it done by converting to a byte array then converting that to a hex string.
short a = 233;
byte[] ret = new byte[2];
ret[0] = (byte)(a & 0xff);
ret[1] = (byte)((a >> 8) & 0xff);
StringBuilder sb = new StringBuilder();
for (byte b : ret) {
sb.append(String.format("%02X ", b));
}
I think that will pretty much do it.