Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created October 18, 2023 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save run-dlang/f07a68f95c4d4b34e9a2b7229cff3e5e to your computer and use it in GitHub Desktop.
Save run-dlang/f07a68f95c4d4b34e9a2b7229cff3e5e to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io. Run with '-unittest'
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