hexToBytes function
The bytes of hex, in lowercase or uppercase. Throws a FormatException
when it is not an even number of hex digits.
Implementation
Uint8List hexToBytes(String hex) {
if (hex.length.isOdd) {
throw const FormatException('Hex has an odd number of digits');
}
final bytes = Uint8List(hex.length ~/ 2);
for (var i = 0; i < bytes.length; i++) {
bytes[i] =
_digitValue(hex.codeUnitAt(2 * i)) << 4 |
_digitValue(hex.codeUnitAt(2 * i + 1));
}
return bytes;
}