I'm a beginner here - this is no doubt easy, but I haven't managed it.
I have lots of places in my program where I need to convert a byte value to a hex string of the form 0xHH.
I can do this as follows:
byte value;
String hex_value = "0x" + String.format("%02x", value);
But this is messy...
Ideally if I've got a byte variable called value, I'd like to be able to include something like value.toHex() in a string expression. How do I do this?
Or is there a better/neater way?
I could extend Byte with a toHex method, but Byte is declared final. How do I get around this?
Thanks - Rowan


Reply With Quote
Bookmarks