MCPcopy Index your code
hub / github.com/oshi/oshi / hexStringToByteArray

Method hexStringToByteArray

oshi-core/src/main/java/oshi/util/ParseUtil.java:282–295  ·  view source on GitHub ↗

Parse a string of hexadecimal digits into a byte array @param digits The string to be parsed @return a byte array with each pair of characters converted to a byte, or empty array if the string is not valid hex

(String digits)

Source from the content-addressed store, hash-verified

280 * empty array if the string is not valid hex
281 */
282 public static byte[] hexStringToByteArray(String digits) {
283 int len = digits.length();
284 // Check if string is valid hex
285 if (!VALID_HEX.matcher(digits).matches() || (len & 0x1) != 0) {
286 LOG.warn("Invalid hexadecimal string: {}", digits);
287 return new byte[0];
288 }
289 byte[] data = new byte[len / 2];
290 for (int i = 0; i < len; i += 2) {
291 data[i / 2] = (byte) (Character.digit(digits.charAt(i), 16) << 4
292 | Character.digit(digits.charAt(i + 1), 16));
293 }
294 return data;
295 }
296
297 /**
298 * Parse a human readable ASCII string into a byte array, truncating or padding

Callers 5

EdidUtilTestClass · 0.95
testToStringMethod · 0.95
parseIpAddrMethod · 0.95
getEdidArraysMethod · 0.95

Calls 1

matchesMethod · 0.80

Tested by 2

testToStringMethod · 0.76