Skip to content

Instantly share code, notes, and snippets.

@gockxml
Created August 27, 2012 12:28
Show Gist options
  • Select an option

  • Save gockxml/3488007 to your computer and use it in GitHub Desktop.

Select an option

Save gockxml/3488007 to your computer and use it in GitHub Desktop.

Revisions

  1. gockxml revised this gist Aug 27, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.py
    Original 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



  2. gockxml created this gist Aug 27, 2012.
    28 changes: 28 additions & 0 deletions gistfile1.py
    Original 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)