Skip to content

Instantly share code, notes, and snippets.

@wandrson
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wandrson/9903871 to your computer and use it in GitHub Desktop.
Save wandrson/9903871 to your computer and use it in GitHub Desktop.
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