Page 1 of 1

Odd and even byte files merge software needed

Posted: Thu Nov 08, 2012 11:01 pm
by jpx72
Can anyone help with fiding a software that can combine two files that were dumped from two eproms that contained one even and the other odd bytes? Thanks!

Re: Odd and even byte files merge software needed

Posted: Thu Nov 08, 2012 11:09 pm
by lidnariq
jpx72 wrote:Can anyone help with fiding a software that can combine two files that were dumped from two eproms that contained one even and the other odd bytes? Thanks!
http://www.lucasforums.com/showpost.php?p=2794290 mentions that WinHex can do this (context: interleaving the MT32 control program from its two 8-bit ROMs) It's also a perl one-liner or C two-liner.

Re: Odd and even byte files merge software needed

Posted: Thu Nov 08, 2012 11:42 pm
by thefox
In Python:

Code: Select all

import io
even = io.open( "even.bin", "rb" ).read()
odd = io.open( "odd.bin", "rb" ).read()
interleaved = "".join( i for j in zip( even, odd ) for i in j )
io.open( "interleaved.bin", "wb" ).write( interleaved )

Re: Odd and even byte files merge software needed

Posted: Fri Nov 09, 2012 12:14 am
by jpx72
Thank you guys! The Winhex (winhex.com) did it (Tools > File tools -> Unify -> Bytewise)!

Re: Odd and even byte files merge software needed

Posted: Fri Nov 09, 2012 7:52 am
by qbradq
Python FTW :D

Re: Odd and even byte files merge software needed

Posted: Fri Nov 09, 2012 1:56 pm
by koitsu
qbradq wrote:Python FTW :D

Code: Select all

interleaved = "".join( i for j in zip( even, odd ) for i in j )
i for j in zip() for i in j

Surely I can't be the only one looking at that going "what the fuck?" So the next time someone tells me Perl is hard to read, I'm going to point them to that line there. I had a discussion with a fellow programmer last night about that line; he broke it down for me (which helped make more sense out of it), and stated boldly in agreement that yes the syntax is utterly retarded. For those still unable to comprehend the clusterfuck, quoting my peer:
you have to read it kind of funny. it's equivalent to

Code: Select all

for j in zip(even, odd):
     for i in j:
         i
the return values get built up into an unnamed list, which becomes the argument to join. the syntax is dumb but the concept is really simple
http://wemeantwell.com/blog/wp-content/ ... up_ass.jpg

Re: Odd and even byte files merge software needed

Posted: Fri Nov 09, 2012 2:00 pm
by tepples
It's not that Python has no warts; it just has far fewer than, say, PHP.

Re: Odd and even byte files merge software needed

Posted: Fri Nov 09, 2012 2:58 pm
by thefox
I actually agree, most of the time I'd write it in a more verbose way.