Skip to content

Instantly share code, notes, and snippets.

@gschizas
Last active August 29, 2015 13:56
Show Gist options
  • Save gschizas/9055136 to your computer and use it in GitHub Desktop.
Save gschizas/9055136 to your computer and use it in GitHub Desktop.
Function HexDump(text)
hexdigits = ""
plaintext = ""
output = ""
For i = 1 to Len(text)
current = Mid(text, i, 1)
hexdigits = hexdigits & Right("0" & Hex(Asc(current)), 2) & " "
if Asc(current) >= 32 And Asc(current) < 127 Then
plaintext = plaintext & current
Else
plaintext = plaintext & "."
End If
If i Mod 16 = 1 Then
output = output & Right("0000" & Hex((i \ 16)*16), 4) & ": "
End If
If i mod 16 = 0 Then
output = output & hexdigits & " | " & plaintext & " |" & vbCrLf
hexdigits = ""
plaintext = ""
End If
Next
rest = Len(text) Mod 16
If rest > 0 Then
hexdigits = hexdigits & Space(3*(16 - rest))
plaintext = plaintext & Space(16 - rest)
output = output & hexdigits & " | " & plaintext & " |" & vbCrLf
End if
HexDump = output
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment