Python 程式進行迴圈冗餘校驗


CRC 用於檢測數字資料中的錯誤,這是一種檢測傳輸錯誤的好技術。此技術主要應用二進位制除法。

在這些技術中,存在迴圈冗餘校驗位,即冗餘位序列,這些位附加到資料單元末尾,使所得資料單元可以被第二個預先確定的二進位制數恰好整除。

在目標端,傳入資料除以相同數字,如果沒有餘數,則認為資料正確並且可以接受。

餘數表示傳輸過程中發生了一些事情,資料單元已損壞。因此,該資料單元不被接受。

Cyclic Redundancy Check

示例程式碼

frompycrc.crclib import *
def main():
#-----------------------------------------------------------------------------
#Sender Side
div = str(input("Input divisor in binary type: "))
#user_dataword = str(raw_input("Input dataword in binary type: "))
userdataword = '1001'
print ("\nSender:")
sen = Sender(bin2dec(userdataword), div)
sen.send()
print ("arg_dataword:", sen.arg_dataword2)
print ("remainder:", sen.remainder2)
print ("codeword:", sen.codeword2)
#-----------------------------------------------------------------------------
#Channel
print ("\nChannel:")
ch = Channel(sen.codeword)
print ("Through to the channel get channel codeword:", dec2bin(ch.ch_codeword))
#-----------------------------------------------------------------------------
#Receiver Side
print ("\nReceiver:")
rcv = Receiver(ch.ch_codeword, div)
rcv.receive()
print ("syndrome:", rcv.syndrome2)
print ("Discard or not?", rcv.discard)
print ("rx_dataword:", rcv.rx_dataword2)
if __name__ == '__main__':
   main()

輸出

Sender
Input dataword in binary type 1010000
arg_dataword:1010000000
remainder: 011
codeword:1010000011
Receiver
syndrome:1010000011
Discard or not? N
rx_dataword:1010000011

更新於: 30-Jul-2019

6K+ 瀏覽

開啟你的 職業 生涯

完成該課程即可獲得認證

立即開始
廣告