hexToByteArray static method

List<int> hexToByteArray(
  1. String inHex
)

hex转字节数组

Implementation

static List<int> hexToByteArray(String inHex) {
  int hexlen = inHex.length;
  Uint8List result;
  if (hexlen % 2 == 1) {
    //奇数
    hexlen++;
    result = Uint8List(hexlen ~/ 2);
    inHex = "0$inHex";
  } else {
    //偶数
    result = Uint8List(hexlen ~/ 2);
  }
  int j = 0;
  for (int i = 0; i < hexlen; i += 2) {
    result[j] = hexToByte(inHex.substring(i, i + 2));
    j++;
  }
  return result;
}