hexToBytes method

Uint8List hexToBytes(
  1. String hex
)

Converts a hexadecimal string to a Uint8List of bytes.

Example:

final bytes = hexToBytes('ff00'); // returns Uint8List.fromList([255, 0])

Implementation

Uint8List hexToBytes(String hex) {
  final result = Uint8List(hex.length ~/ 2);
  for (int i = 0; i < hex.length; i += 2) {
    result[i ~/ 2] = int.parse(hex.substring(i, i + 2), radix: 16);
  }
  return result;
}