#!/usr/bin/python import sys import struct f = open(sys.argv[1], 'rb') while 1: count = struct.unpack_from("8H", f.read(16)) #format intel hex format output buffer buf = ":"+("%0.2X" % count[0])+("%0.4X" % addr[0])+("%0.2X" % type[0]) for ad in data: buf+=("%0.4X" % ad) chksum = 0 for b in data: chksum += int(b) #calculate checksum chksum = (chksum % (0x100))^0xff buf+="%0.2X" % chksum print buf f.read(1) #if type 1(end of file), then exit if type[0] == 1: break