Skip to content

Instantly share code, notes, and snippets.

@jsantanders
Created November 27, 2016 03:35
Show Gist options
  • Select an option

  • Save jsantanders/bd8d74d7c1ed2a325c20c28d63ebc76e to your computer and use it in GitHub Desktop.

Select an option

Save jsantanders/bd8d74d7c1ed2a325c20c28d63ebc76e to your computer and use it in GitHub Desktop.

Revisions

  1. Jesus Alberto created this gist Nov 27, 2016.
    19 changes: 19 additions & 0 deletions mod2.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    binCrcGen = [1, 0, 0, 1]
    s=0b1101010010111
    binPayload = [int(d) for d in str(bin(s))[2:]]


    while len(binCrcGen) <= len(binPayload) and binPayload:
    if binPayload[0] == binCrcGen[0]:
    del binPayload[0]
    for j in range(len(binCrcGen)-1):
    binPayload[j] ^= binCrcGen[j+1]
    print(binPayload, "binPayload")
    while binPayload and binPayload[0] == 0:
    del binPayload[0]
    print(binPayload, "binPayload")

    str1 = ''.join(str(e) for e in binPayload)
    ces = int(str1,2)
    ct = format(ces, 'b').zfill(4)
    print(ct)