CRC program design purpose: by writing a CRC verification program, we can deepen our understanding of the CRC principle. At the same time, we can learn how to apply the Principles in books to the actual situation, so that we can learn more quickly. Note: the part about the CRC principle in this article is collected from the network. 1. Requirement Analysis
Write a simulation program for CRC verification. The program implements the following functions: input: a string of binary bits
Output: CRC verification code 2. CRC verification principle analysis here, we mainly analyze the CRC verification algorithm principle from the perspective of programming implementation, not just the introduction of the CRC principle in books. Cyclic Redundancy Check Cyclic Redundancy test is a set of verification codes based on data computing. It is used to Check whether the data is changed or transmitted incorrectly during transmission.
Assume that 15-bit binary information g = 101001110100001 needs to be sent during data transmission. The binary code can be expressed as an algebraic polynomial g (x) = x ^ 14 + x ^ 12 + x ^ 9 + x ^ 8 + x ^ 7 + x ^ 5 + 1, where the k-bit value in g, corresponds to the x ^ k coefficient in g (x. Multiply g (x) by x ^ m, then add m 0 after g, and divide it by h (x) of the degree m polynomial, and obtain the remainder of m-1) degree r (x) the corresponding binary code r is CRC encoding.
H (x) can freely choose or use international standard, generally according to h (x) Order m, CRC algorithm called CRC-m, such as CRC-8, CRC-32, CRC-64, etc.
Division operations of g (x) and h (x) can be performed through g and h xor exclusive or. For example, perform xor operations on 11001 and 10101: 650) this. width = 650; "alt =" "src =" http://img1.51cto.com/attachment/200907/200907121247409820833.bmp "border =" 0 "/> for example, using a CRC-8 algorithm to calculate a 101001110100001 verification code. CRC-8 standard h (x) = x ^ 8 + x ^ 7 + x ^ 6 + x ^ 4 + x ^ 2 + 1, that is, h is a 9-bit binary string 111010101. 650) this. width = 650; "alt =" "src =" http://img1.51cto.com/attachment/200907/200907121247410050083.bmp "border =" 0 "/> after iteration, the final r is 10001100, which is the CRC verification code. 3. Outline Design
Based on the above principles, we have made initial planning and design for the software: 1) Since h (x) has various standards, their principles are similar, therefore, we use CRC-8 standards to achieve CRC verification simulation.
2) according to the above algorithm principle, the program needs to use arrays or queues to store and operate data. Because c ++ supports many encapsulated containers to organize data, for example, the Deque container can use the c ++ language to perform the required functions more efficiently. Therefore, our programming language uses c ++.
3) to provide a friendly user interface, we use the Visual C ++ MFC framework to build an application. A simple dialog box contains an input and edit box and an output edit box.
4. Detailed design 4.1 Data Structure Design
Define three bool-type queues, deque <bool>, which respectively represent the input string register, Operation string register, and remaining string register.
Where:
Input string register: used to store user input binary strings
Operation string register: used to store the current subtrahend
Remaining string register: used to store the remaining part of the input string register that has not entered the operation string register. Define a bool array and store Hx)
Const int CRC8_HX_LENGTH = 9; // use the CRC-8 algorithm, so the length of H (x) is 9
Bool hx [CRC8_HX_LENGTH] = {1, 1, 0, 1, 0, 1 };//! <H (x)
Define two Cstring variables to store input and output data.
4.2 module division 650) this. width = 650; "alt =" "src =" http://img1.51cto.com/attachment/200907/200907121247410293092.bmp "border =" 0 "/> module function Overview:
Input module: obtains the user's input binary string and determines whether the input is correct.
Register initialization module: converts a user's input string into a numeric string in the form of 0 or 1 and stores it in the input string register. The first nine digits are retrieved and stored in the Operation register as the current subtrahend.
Verification code calculation module: returns or returns the result of each digit of the Operation register corresponding to the Hx, and stores the result in the corresponding position of the Operation register.
Operation register shift module: This module leaves all the 0 operators in the current operation register queue, and adds the corresponding number of data from the remaining registers to the end of the operation register queue for the next operation.
Display Module: converts the final CRC verification code of the Operation Register into a string for output. 4.3 program flowchart 650) this. width = 650; "alt =" "src =" http://img1.51cto.com/attachment/200907/200907121247410361340.bmp "border =" 0 "/> 5 program running and verification 650) this. width = 650; "alt =" "src =" http://img1.51cto.com/attachment/200907/200907121247410747676.bmp "border =" 0 "/>
Input string verification 650) this. width = 650; "alt =" "src =" http://img1.51cto.com/attachment/200907/200907121247410800782.bmp "border =" 0 "/>
This article from the "three shadows" blog, please be sure to keep this source http://ticktick.blog.51cto.com/823160/176981