Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. from math import frexp
  2. log2 = lambda x: frexp(x)[1]-1
  3.  
  4. transpose = lambda l: map(list, zip(*l))
  5.  
  6. def to_binary(number, pad_to):
  7.     '''NUMBER is the number you want in binary.
  8.       PAD_TO is the length of final string you want.'''
  9.     return str("{0:b}".format(number)).zfill(pad_to)
  10.  
  11. n = 16 # number of samples
  12. m = log2(n) # number of tests
  13. tests = []
  14. for i in range(n):
  15.     tests.insert(0, to_binary(i, pad_to = m))
  16. for i, test in enumerate(transpose(tests)):
  17.     print "Test #"+str(i)+": "+"".join(test)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement