Created
January 29, 2016 07:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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