hexZuBytes function

List<int>? hexZuBytes(
  1. String hex
)

Hex zu Bytes; null bei ungerader Laenge oder Nicht-Hex.

Implementation

List<int>? hexZuBytes(String hex) {
  if (hex.isEmpty || hex.length.isOdd || !RegExp(r'^[0-9a-fA-F]+$').hasMatch(hex)) return null;
  final bytes = List<int>.filled(hex.length ~/ 2, 0);
  for (var i = 0; i < bytes.length; i++) {
    bytes[i] = int.parse(hex.substring(i * 2, i * 2 + 2), radix: 16);
  }
  return bytes;
}