- for (i = 0; i < n; i++)
- r[i] = hexbyte(s, i * 2);
+ for (i = 0; i < n; i++) {
+ int h = fromhex(bytes[(i << 1)]);
+ int l = fromhex(bytes[(i << 1) + 1]);
+ if (h < 0 || l < 0)
+ throw new NumberFormatException(String.format("invalid hex \"%c%c\"",
+ bytes[(i<<1)], bytes[(i<<1) + 1]));
+ r[i] = (h << 4) + l;
+ }