Created
August 27, 2012 12:28
-
-
Save gockxml/3488007 to your computer and use it in GitHub Desktop.
Revisions
-
gockxml revised this gist
Aug 27, 2012 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -22,6 +22,7 @@ def generate(id, align = 8): result = int(''.join(map(lambda s:str(s), temp + temp2)), 2) print "result : ", result return result -
gockxml created this gist
Aug 27, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ import math def generate(id, align = 8): a = bin(id)[2:] bin_align = int(math.log(10 ** align, 2)) fill_a = a.rjust(bin_align, '0') left = fill_a[: bin_align / 2] right = fill_a[bin_align / 2:] temp = [int(right[-1])] for i in right[::-1][1:]: temp.append(temp[-1] ^ int(i)) print "fill_a : ", fill_a print "right part : ", temp temp2 = [] for i in range(0, len(left)): temp2.append(int(left[i]) ^ int(right[i])) print "left part : ", temp2 result = int(''.join(map(lambda s:str(s), temp + temp2)), 2) print "result : ", result generate(10)