Skip to content

Instantly share code, notes, and snippets.

@fjolnir
Created May 10, 2017 06:57
Show Gist options
  • Save fjolnir/bf516f8f126a7dbb12a6c641a48b3f10 to your computer and use it in GitHub Desktop.
Save fjolnir/bf516f8f126a7dbb12a6c641a48b3f10 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
def hexdump(src, length=16):
lines = []
for c in xrange(0, len(src), length):
chars = src[c:c+length]
hex = ' '.join(["%02x" % ord(x) for x in chars])
printable = ''.join(["%s" % ((ord(x) <= 127 and x) or '.') for x in chars])
lines.append("%04x %-*s %s\n" % (c, length*3, hex, printable))
return ''.join(lines)
print hexdump("XW?LS?あb")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment