Skip to content

Instantly share code, notes, and snippets.

@sudevschiz
Created January 29, 2016 07:10
Show Gist options
  • Save sudevschiz/dc247fef1119d69fcae0 to your computer and use it in GitHub Desktop.
Save sudevschiz/dc247fef1119d69fcae0 to your computer and use it in GitHub Desktop.
Script to get binary values of number range. Useful to generate continuous truth table for many observations
import csv
#Specify start and end values in decimal
range_start = 1
range_stop = 2^15
with open('output_file.csv','w') as out_file:
for i in range(range_start,range_stop):
#Specify how many bits should be present in the converted binary. 15 in this case
bi = '{0:15b}'.format(i)
#Converts string to list
sp = list(str(bi))
#print str(sp)
#Write to csv with a , delimiter
writer = csv.writer(out_file, delimiter=',')
writer.writerow(sp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment