code: def hexdump(buf, num_bytes, offset=0, width=32):
      
      ind = offset
      end = offset + num_bytes
      lines = []
      while ind < end:
          chunk = buf[ind:ind + width]
          actual_width = len(chunk)
          hexfmt = '{:02X}'
          blocksize = 4
          blocks = [hexfmt * blocksize for _ in range(actual_width // blocksize)]
  
          # Need to get any partial lines
          num_left = actual_width % blocksize  # noqa: S001  Fix false alarm
          if num_left:
              blocks += [hexfmt * num_left + '--' * (blocksize - num_left)]
          blocks += ['--' * blocksize] * (width // blocksize - len(blocks))
  
          hexoutput = ' '.join(blocks)
          printable = tuple(chunk)
          lines.append('  '.join((hexoutput.format(*printable), str(ind).ljust(len(str(end))),
                                  str(ind - offset).ljust(len(str(end))),
                                  ''.join(chr(c) if 31 < c < 128 else '.' for c in chunk))))
          ind += width
      return '\n'.join(lines)
docs: Perform a hexudmp of the buffer.
  
      Returns the hexdump as a canonically-formatted string.