[ create a new paste ] login | about

Link: http://codepad.org/ekfw3UZg    [ raw code | output | fork ]

Python, pasted on Jun 3:
1
2
3
4
5
6
7
8
9
10
11
def hexdump(src, length=16):
    FILTER = ''.join([(len(repr(chr(x))) == 3) and chr(x) or '.' for x in range(256)])
    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 FILTER[ord(x)]) or '.') for x in chars])
        lines.append("%04x  %-*s  %s\n" % (c, length*3, hex, printable))
    return ''.join(lines)

print hexdump("python is awesome, i'm addict")


Output:
1
2
3
0000  70 79 74 68 6f 6e 20 69 73 20 61 77 65 73 6f 6d   python is awesom
0010  65 2c 20 69 27 6d 20 61 64 64 69 63 74            e, i'm addict



Create a new paste based on this one


Comments: