import strutils
proc hexDump*(s: string | cstring, cols: int = 16, offs: int = 2): string =
result = newStringOfCap(s.len * 3 - 1 + (s.len div cols + 1) * (offs + 2))
var newLine = true
for idx, c in s:
if idx > 0:
if idx mod cols == 0:
result.add "\n"
newLine = true
else:
result.add ' '
if newLine:
newLine = false
result.add idx.toHex offs
result.add ": "
result.add ord(c).toHex 2
echo hexDump("0123456789ABCDEF\nHello World! The Hexdump!")