Skip to content

Instantly share code, notes, and snippets.

@LTe
Created June 6, 2010 19:37
Show Gist options
  • Save LTe/427823 to your computer and use it in GitHub Desktop.
Save LTe/427823 to your computer and use it in GitHub Desktop.
plik = File.open("intel.hex", "r")
hex = plik.readlines
binfile = []
hex.each do |line|
adress = line[3..6]
type = line[7..8]
data = line[9..40]
checksum = line[41..42]
puts "Ad: #{adress}, type: #{type}, data: #{data}, checksum: #{checksum} | #{adress.to_i(16) / 16} |"
binfile[adress.to_i(16) / 32] = data.unpack("H32")
end
binfile.inspect
binfile.collect! {|x|
if(x == nil)
x = ("0"*16)
else
x = x
end
}
puts binfile.join.inspect
result = binfile.join
result = result.split(//)
result.each_index { |x|
if(x % 32 == 0)
puts ":count||adress||#{result[x..x+32]}"
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment