import binascii


def bin_compare_bytes(f1, f2, st_addr, size_bytes):
  """compare two binary files from start addr

  :param f1: first file to compare.
  :param f2: second file to compare.
  :param st_addr: start address to compare
  :param size_bytes: size of bytes to compare.
  :returns rtn: True/False
  """
  rtn = True
  with open(f1, 'rb') as fp1, open(f2, 'rb') as fp2:
    fp1.seek(st_addr), fp2.seek(st_addr)
    total, bufsize = 0, 16
    while total < size_bytes:
      temp1, temp2 =fp1.read(bufsize), fp2.read(bufsize)
      total += 16
      if temp1 != temp2:
        print("index: 0x%x"%(st_addr+total))
        print("%-30s"%f1, binascii.hexlify(temp1))
        print("%-30s"%f2, binascii.hexlify(temp2))
        rtn=False
  return rtn