Skip to content

Instantly share code, notes, and snippets.

@wandrson wandrson/long2bin.py
Last active Aug 29, 2015

Embed
What would you like to do?
This python program will convert up to a specified maximum number of 32-bit numbers to a binary file.
#! /usr/bin/python
import sys
import struct
try:
infilename = sys.argv[1]
outfilename = sys.argv[2]
maxsize = int(sys.argv[3])
except:
print "ERROR! ./long2bin.py infile (txt) outfile (binary) maximum_size"
exit(0)
infp = open(infilename,"r")
outfp = open(outfilename,"wb")
count = 0
while (count < maxsize):
line = infp.readline()
if not line:
break
value = int(line)
count += 1
outfp.write(struct.pack('=L',value))
outfp.close()
infp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.