I am starting to do a new big project so I started to learn about CRC(Cyclic redundancy check). After I had learned about it, I made one (CRC-16, with polynomial x^16+x^15+x^2+1, that equal to hex 0x8005), But when I checked if I did it fine, I found out it right but not the answer I wanted to get. I am using the website: http://crccalc.com/ In the code, I entered the binary value: 0100010101010011 (equal to 0x4553) and got the result is 1001111111101100 ( equal to 0x9FEC) I found out on the website is the right result but it not what I expected to get(I thought I'd get 0xAD72).
I have two questions:
How do I change my code to support CRC-16/ARC and not CRC-16/BUYPASS?
Why the polynomial x^16+x^15+x^2+1 equal to 0x8005 and not 0xC005? Thanks a lot!
my python code:
def stXor(a,b):
if(a==b):
return "0"
else:
return "1"
def stshl(str1,shift):
temp=""
temp=str1
for i in range(shift):
temp=temp[1:]
return temp
def get_error(data,padding=True):
good=data
lst=["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]
if(padding):
good=data+"0"*16
now="0"
while len(good)>0:
now=lst[0]
lst[0]= stXor(lst[1],now) #x^15
lst[1]=lst[2]
lst[2]=lst[3]
lst[3]=lst[4]
lst[4]=lst[5]
lst[5]=lst[6]
lst[6]=lst[7]
lst[7]=lst[8]
lst[8]=lst[9]
lst[9]=lst[10]
lst[10]=lst[11]
lst[11]=lst[12]
lst[12]=lst[13]
lst[13]=stXor(lst[14],now)# x^2
lst[14]=lst[15]
lst[15]=stXor(good[0],now)
good=stshl(good,1)
a=""
for letter in lst:
a+=letter
return a
data="0100010101010011"
print("data entered: "+"\nhex: "+str(hex(int(data, 2)))+"\nBinary: "+data)
a=get_error(data)
print("Result: "+"\nhex: "+str(hex(int(a, 2)))+"\nBinary: "+a)
printed output:
data entered:
hex: 0x4553
Binary: 0100010101010011
Result:
hex: 0x9fec
Binary: 1001111111101100
0xC003come from?0xC005come from?