Gistrec

HEX dump

Feb 2nd, 2019
199
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. function hex_dump($data, $newline="\n"){
  2.     static $from = '';
  3.     static $to = '';
  4.  
  5.     static $width = 16; # number of bytes per line
  6.  
  7.     static $pad = '.'; # padding for non-visible characters
  8.  
  9.     if ($from==='') {
  10.         for ($i=0; $i<=0xFF; $i++){
  11.             $from .= chr($i);
  12.             $to .= ($i >= 0x20 && $i <= 0x7E) ? chr($i) : $pad;
  13.         }
  14.     }
  15.  
  16.     $hex = str_split(bin2hex($data), $width*2);
  17.     $chars = str_split(strtr($data, $from, $to), $width);
  18.  
  19.     $offset = 0;
  20.     foreach ($hex as $i => $line) {
  21.       echo sprintf('%6X',$offset) . ' : ' .implode(' ', str_split($line,2)) .
  22.            ' [' . $chars[$i] . ']' . $newline;
  23.       $offset += $width;
  24.     }
  25. }
Comments
  • User was banned
Add Comment
Please, Sign In to add comment