* Convert a single hex-nibble to a byte. * * @param c The hex-nibble to convert. * @return The byte the hex-nibble represents, or -1 if it is not a valid hex-nibble. */
| 549 | * @return The byte the hex-nibble represents, or -1 if it is not a valid hex-nibble. |
| 550 | */ |
| 551 | static int ConvertHexNibbleToByte(char c) |
| 552 | { |
| 553 | if (c >= '0' && c <= '9') return c - '0'; |
| 554 | if (c >= 'A' && c <= 'F') return c + 10 - 'A'; |
| 555 | if (c >= 'a' && c <= 'f') return c + 10 - 'a'; |
| 556 | return -1; |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * Convert a hex-string to a byte-array, while validating it was actually hex. |