On Nov 28, 2011, at 2:37 PM, Chuck Guzis wrote:
On 28 Nov 2011 at 11:04, Fred Cisin wrote:
Surely you can reduce it to much less than 12
lines in "high level"
languages!
High level? For me, it's usually faster to use DEBUG on the file and
write a little code than to go looking for a program.
In Python, you could do the following interactively (it reads the whole thing into memory
first, but any modern machine shouldn't have trouble with that, and it's really
short):
----
in_data = open("infile.bin", "rb").read()
open("even.bin", "wb").write(in_data[0::2])
open("odd.bin", "wb").write(in_data[1::2])
----
If you wanted to be more memory efficient, you could do it the old-fashioned way, though
Python actually gets in your way about it a little bit:
----
infile = open("infile.bin", "rb")
outfiles = [open(x, "wb") for x in ["even.bin", "odd.bin"]]
while infile.peek():
for f in outfiles:
f.write(infile.read(1))
----
That also has the benefit of fairly easily allowing arbitrary interleaving (if you had 4
ROMS for a 32-bit system, say). There's probably a nicer way of doing it than using
file.peek(), but since there's no feof() equivalent for the file object, it'll
do.
- Dave