convert method
Converts input
and returns the result of the conversion.
Implementation
@override
List<int> convert(String hex) {
String str = hex.replaceAll(" ", "");
str = str.toLowerCase();
if (str.length % 2 != 0) {
str = "0" + str;
}
Uint8List result = new Uint8List(str.length ~/ 2);
for (int i = 0; i < result.length; i++) {
int firstDigit = _ALPHABET.indexOf(str[i * 2]);
int secondDigit = _ALPHABET.indexOf(str[i * 2 + 1]);
if (firstDigit == -1 || secondDigit == -1) {
throw new FormatException("Non-hex character detected in $hex");
}
result[i] = (firstDigit << 4) + secondDigit;
}
return result;
}