def hex_dump(binstr):
  """Convert binary string into its multiline hex representation."""

  dump_lines = ['',]
  i = 0
  while i < len(binstr):
    strsize = min(16, len(binstr) - i)
    hexstr = ' '.join('%2.2x' % ord(x) for x in binstr[i:i+strsize])
    dump_lines.append(hexstr)
    i += strsize
  dump_lines.append('')
  return '\n'.join(dump_lines)