# MiscEl: CRC and checksum

 Back to MiscEl main page Write a message to author Calculate crc and/or checksums, many different algorithms and data formats.
Checksums Simple datacheck
modulus Number check, usual used for manuel entry and barcode number check

### Algorithm

 CRC 8 CRC with 8 bit polynomial, a useable polynomial is \$07, see CRC calculations for coding examples CRC 16 CRC with 16 bit polynomial, see CRC calculations for coding examples CRC 16 std Use the \$8005 polynomial, see CRC calculations for coding examples CRC 16 CCITT Use the \$1021 polynomial, see CRC calculations for coding examples CRC 32 CRC with 32 bit polynomial, see CRC calculations for coding examples CRC 32 std. Use the \$04C11DB7 polynomial, see CRC calculations for coding examples CRC 32 I.363 Same as above, but other settings, see CRC calculations for coding examples Checksum Add all bytes Checksum with zero result Add all bytes and negate the result Xor Xor all bytes 16 bit checksum Add all bytes in a 16 bit register Modulus Modulus check, used for numerical strings Modulus 10 arithmetic Mod 10 with 21 weights Modulus 10 geometric Mod 10 with 731 weights Modulus 10 MSI Mod 10 with 21 weights and "SumDigits" Modulus 10 UPC/EAN Mod 10 with 13 weights Modulus 11 arithmetic Mod 11 with 234567 weights Modulus 11 geometric Mod 11 with 2,4,8,5,10,9,7,3,6,1 weights Modulus 11 danish CPR Mod 11 with 765432 weights Guess with checksum Try to guess a checksum algorithm from a known checksum. Guess Try to guess what checksum algorithm was used on the data. It is assumed that the last databyte(s) contains the checksum. Data view List all the data in hex format, used to verify that the input is correctly read

### Data format

It is very important to select the correct dataformat!
 Hex/Text A mix of numbers and text strings. Any number is supposed to be in hex and text must have quotes around it Expression Same syntax as in Calculator, expression can be delimetered with ; Hex dump Will decode typical hex dumps formats. I.e.: "address data text", the address and data fields are required, the text field is optional Text Any text, leading and trailing spaces and newlines are ignored Text and spaces Any text, only newlines are ignored

### Parameters

 Initial Initial value for calculations Alt Another way to express the same initial value, the releation between "Initial" and "Alt" will depend on the agorithm Final Xor Invert some or all of the result bits Polynom The CRC polynomial, X^(n-1) first and X^0 last, X^n is assumed to be 1 Inverted The CRC polynomial, X^0 first and x^(n-1) last, x^n is assumed to be 1 Reverse data Reverse (reflect) data bits before procession Reverse result Reverse (reflect) result bits after procession, usual used together with "Reverse data" Modulus Modulus usual 10 or 11, but other values can be used. For digits above 9 use letters (A=10, B=11 etc.) Weights Values to multiply the digits with.The weights are specied as a list of numbers Reminder Reminder to display, usual calculated as "modulus-reminder"The reminders are specied as a list of numbers, one for each reminder value Apply weight from left Select between applying weight from left or right Sum digits In modulus the sum is calculated from the weights. I.e. a 9 digit with a 3 weight adds 9*3=27 to the weight, but when this parameter is checked it will give 2+7=9 to the weight Edit params Press this buttoms to copy the parameters to the generic algorithm

### Output

The first part of the output is just a list of the parameters used.
Some values are also listet as ascii values, this is a combination of characters, character names and hex values
When doing modulus checks, two calculations are done:
1) A modulus digit is calculated for the number
2) The number is assumed to contain a modulus digit and a check is performed

To get a pregenerated crc table, select the data format with the "Save format" checkbox and press "Save".
CaveatDo not specify an inverted polynom, when "Reverse data" are checkmarked the necessary bit manipulation are done automatic.

### Hints

• When using crc the polynom is very important for the quality of the data check (i.e. do not make your own polynom, but use a verified one).
• To check a small (<64K) file use "DataFormat=Expression" and "Data=FileLoad("filename")"
• CRC often uses reverse data to simulate the bitstream of a serial line with lsb first
• A CRC must have a non-zero initial value to protect leading \$00 bytes
• CRC algorithms exist in two flavors: normal and inverted. They give the same result when handled correctly
• The CRC function in the Calculator is using the reversed algorithm, this also means that it is working with reverse data
• Different types of MSI modulus check exists.
• See CRC calculations for coding examples

### Calculator functions

The Calculator also support some crc calculations:
``` CRC8(poly,initial,string) CRC16(poly,initial,string) CRC32(poly,initial,string) CRCPoly(coefficients) CRCPolyReverse(ReversePolyValue) ```

### Other pages

• MPU Support list where MiscEl can help when working with microprocessors