Created
July 10, 2021 17:41
-
-
Save Hexer10/f57f9451114ae96f6207a6c762517902 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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