Created
October 18, 2023 21:40
-
-
Save run-dlang/f07a68f95c4d4b34e9a2b7229cff3e5e to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io. Run with '-unittest'
This file contains hidden or 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
void main() | |
{ | |
import std.algorithm, std.stdio, std.file, std.range; | |
enum cols = 14; | |
// Split file into 14-byte chunks per row | |
thisExePath.File("rb").byChunk(cols).take(20).each!(chunk => | |
// Use range formatting to format the | |
// hexadecimal part and align the text part | |
writefln!"%(%02X %)%*s %s"( | |
chunk, | |
20, "xxxx", | |
//3 * (cols - chunk.length), "", // Padding | |
map!(c => // Replace non-printable | |
c < 0x20 || c > 0x7E ? '.' : char(c))(chunk))); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment