docs: def bintoihex(buf, spos=0x0000):
      """Convert binary buffer to ihex and return as string."""
      c = 0
      olen = len(buf)
      ret = ""
      # 16 byte lines
      while (c+0x10) <= olen:
          adr = c + spos
          l = ':10{0:04X}00'.format(adr)
          sum = 0x10+((adr>>8)&M8)+(adr&M8)
          for j in range(0,0x10):
              nb = buf[c+j]
              l += '{0:02X}'.format(nb)
              sum = (sum + nb)&M8
          l += '{0:02X}'.format((~sum+1)&M8)
          ret += l + '\n'
          c += 0x10
      # remainder
      if c < olen:
          rem = olen-c
          sum = rem
          adr = c + spos
          l = ':{0:02X}{1:04X}00'.format(rem,adr)   # rem < 0x10
          sum += ((adr>>8)&M8)+(adr&M8)
          for j in range(0,rem):
              nb = buf[c+j]
              l += '{0:02X}'.format(nb)
              sum = (sum + nb)&M8
          l += '{0:02X}'.format((~sum+1)&M8)
          ret += l + '\n'
      ret += ':00000001FF\n'        # EOF
      return ret