Created
November 27, 2016 03:35
-
-
Save jsantanders/bd8d74d7c1ed2a325c20c28d63ebc76e to your computer and use it in GitHub Desktop.
Revisions
-
Jesus Alberto created this gist
Nov 27, 2016 .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,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)