79826664

Date: 2025-11-21 15:14:15
Score: 0.5
Natty:
Report link

In newer Java Versions (since 17) there is HexFormat:

     byte byteVal = (byte)HexFormat.of().fromHexDigits("7f");
     assert(byteStr.equals("7f"));
     assert(b == byteVal);

     HexFormat commaFormat = HexFormat.ofDelimiter(", ").withPrefix("#");
     byte[] bytes = {0, 1, 2, 3, 124, 125, 126, 127};
     String str = commaFormat.formatHex(bytes);

     byte[] parsed = commaFormat.parseHex(str);
     assert(Arrays.equals(bytes, parsed));

     // The formatted string is: "#00, #01, #02, #03, #7c, #7d, #7e, #7f"

https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/HexFormat.html

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Manuel_B