Having given a command line parameter which is a hex string I use org.apache.commons.codec.binary.Hex.decodeHex to get a byte[].
But of course Java bytes are signed. I'd like to treat this as a bunch of unsigned bytes (so where I have a byte value of, say, -128 I want it to be 0x80 = 128, or for -103 I want it to be 0x99 = 153.
It's not going to fit in a byte[] anymore, so let's make it a char[] (short[] would also work).
What is the way to do this in Java. I can write the obvious loop (or better: stream pipeline) but is there something better, built-in, e.g. some library method that I'm unaware of?
- This isn't something
java.nio.ByteBufferdoes java.nio.charset.CharsetDecoderhas an API with the right signature but I don't know if there is (or how to get) an "identity" decoder.
(No work to show: internet searches turned up nothing like this.)