GItHub上的Bin2Mem竟然不能在Windows x64下使用,只好自己写一个了。
原理大致就是按字符读取,然后将一个字符(char=8位)转换为2位16进制数(hex=16=4位2进制数)
name = "calcu"
filepath = name+".bin"
targetpath = name+".data"
target = open(targetpath, "w")
binfile = open(filepath, 'rb')
i = 0
ch = binfile.read(1)
target.write ("memory_initialization_radix = 16;\n")
target.write ("memory_initialization_vector = \n")
while ch:
data = ord(ch)
target.write ("%02X" %(data))
if i % 4 == 3:
target.write ("\n")
i = i + 1
ch = binfile.read(1)
target.write (";")
binfile.close()