hexToU8 method

Uint8List hexToU8(
  1. String hex
)

Convert hex string to Uint8List

Implementation

Uint8List hexToU8(String hex) {
  if (hex.length % 2 == 1) {
    hex = "0" + hex;
  }

  int len = hex.length ~/ 2;
  Uint8List u8 = new Uint8List(len);

  var j = 0;
  for (int i = 0; i < len; i++) {
    u8[i] = int.parse(hex.substring(j, j + 2), radix: 16);
    j += 2;
  }

  return u8;
}