Created
          November 27, 2013 23:01 
        
      - 
      
- 
        Save bNull/7684598 to your computer and use it in GitHub Desktop. 
    python hexdump
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def hexdump(src, length=16, sep='.'): | |
| """Modified from: https://gist.github.com/7h3rAm/5603718 | |
| """ | |
| FILTER = ''.join([(len(repr(chr(x))) == 3) and chr(x) or sep 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]) | |
| if len(hex) > 24: | |
| hex = "%s %s" % (hex[:24], hex[24:]) | |
| printable = ''.join(["%s" % ((ord(x) <= 127 and FILTER[ord(x)]) or sep) for x in chars]) | |
| lines.append("%08x: %-*s |%s|\n" % (c, length*3, hex, printable)) | |
| return ''.join(lines).rstrip() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment