Skip to content

Instantly share code, notes, and snippets.

@Hexer10
Created July 10, 2021 17:41
Show Gist options
  • Save Hexer10/f57f9451114ae96f6207a6c762517902 to your computer and use it in GitHub Desktop.
Save Hexer10/f57f9451114ae96f6207a6c762517902 to your computer and use it in GitHub Desktop.
String prettyHex(List<int> bytes, int length) {
final buffer = StringBuffer();
for (var i = 0; i < bytes.length; i += length) {
final list = bytes.sublist(i, min(i + length, bytes.length));
final l1 = list.map((e) => e.toRadixString(16).padLeft(2, '0')).toList();
final l2 = list.map((e) {
if (e > 0 && e < 128) {
return ascii.decode([e]);
}
return '.';
}).toList();
buffer.writeln('${l1.join(' ').padRight(length * 3)} | ${l2.join()}');
}
return buffer.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment