Online CRC Calculation
Be careful: there are several ways to realize a CRC. They differ (at least) in the way which bit is shifted in first and also in the initialization of the flipflops.

Enter your CRC polynomial as bit sequence ("100110001") here:

This gives the following CRC polynomial (press RETURN to update):

P(x) = x10+ x9+ x5+ x4+ x1+ x0

Enter your message as sequence of hex bytes here. Don't care about whitespaces since they will be ignored.

Press RETURN or the Calculate button below to see the CRC checksum here:

0000000000 is the initial CRC value        (hide details)
Next hex digit [1]:
   Shift in of [0] results in 0000000000
   Shift in of [0] results in 0000000000
   Shift in of [0] results in 0000000000
   Shift in of [1] results in 1000110011
Next hex digit [f]:
   Shift in of [1] results in 0001100110
   Shift in of [1] results in 1011111111
   Shift in of [1] results in 0111111110
   Shift in of [1] results in 0111001111
Next hex digit []:
Next hex digit [f]:
   Shift in of [1] results in 0110101101
   Shift in of [1] results in 0101101001
   Shift in of [1] results in 0011100001
   Shift in of [1] results in 1111110001
Next hex digit [f]:
   Shift in of [1] results in 1111100010
   Shift in of [1] results in 1111000100
   Shift in of [1] results in 1110001000
   Shift in of [1] results in 1100010000
Next hex digit []:
Next hex digit [3]:
   Shift in of [0] results in 0000010011
   Shift in of [0] results in 0000100110
   Shift in of [1] results in 1001111111
   Shift in of [1] results in 0011111110
Next hex digit [0]:
   Shift in of [0] results in 0111111100
   Shift in of [0] results in 1111111000
   Shift in of [0] results in 0111000011
   Shift in of [0] results in 1110000110
Next hex digit []:
Next hex digit [0]:
   Shift in of [0] results in 0100111111
   Shift in of [0] results in 1001111110
   Shift in of [0] results in 1011001111
   Shift in of [0] results in 1110101101
Next hex digit [4]:
   Shift in of [0] results in 0101101001
   Shift in of [1] results in 0011100001
   Shift in of [0] results in 0111000010
   Shift in of [0] results in 1110000100
Next hex digit []:
Next hex digit [0]:
   Shift in of [0] results in 0100111011
   Shift in of [0] results in 1001110110
   Shift in of [0] results in 1011011111
   Shift in of [0] results in 1110001101
Next hex digit [5]:
   Shift in of [0] results in 0100101001
   Shift in of [1] results in 0001100001
   Shift in of [0] results in 0011000010
   Shift in of [1] results in 1110110111
Next hex digit []:
Next hex digit [3]:
   Shift in of [0] results in 0101011101
   Shift in of [0] results in 1010111010
   Shift in of [1] results in 0101110100
   Shift in of [1] results in 0011011011
Next hex digit [4]:
   Shift in of [0] results in 0110110110
   Shift in of [1] results in 0101011111
   Shift in of [0] results in 1010111110
   Shift in of [0] results in 1101001111
Next hex digit []:
Next hex digit [a]:
   Shift in of [1] results in 1010011110
   Shift in of [0] results in 1100001111
   Shift in of [1] results in 1000011110
   Shift in of [0] results in 1000001111
Next hex digit [7]:
   Shift in of [0] results in 1000101101
   Shift in of [1] results in 0001011010
   Shift in of [1] results in 1010000111
   Shift in of [1] results in 0100001110
$ 10e(hexadecimal)
% 0100001110(binary)
! 270(decimal)



A typical hardware implementation (LFSR - Linear Feedback Shift Register) is shown here:


Dr.-Ing. K. Gorontzi, 2005

The input bits are shifted into the very left XOR gate. The MSB (leftmost bit) of each byte is shifted in first.

Each flipflop represents a single CRC output bit. The leftmost flipflop is the MSB of the CRC. This implementation doesn't need to augment the serial input message with zeros.

Note that in our case the flipflops are cleared to zeros at the beginning of each CRC calculation.




A simple VERILOG implementation of the above polynom is shown here. You can directly copy the source snippet to your code (distributed under LGPL):


// ==========================================================================
// CRC Generation Unit - Linear Feedback Shift Register implementation
// (c) Kay Gorontzi, GHSi.de, distributed under the terms of LGPL
// ==========================================================================
module CRC_Unit(BITVAL, BITSTRB, CLEAR, CRC);
   input        BITVAL;                            // Next input bit
   input        BITSTRB;                           // Current bit valid (Clock)
   input        CLEAR;                             // Init CRC value
   output [9:0] CRC;                               // Current output CRC value

   reg    [9:0] CRC;                               // We need output registers
   wire         inv;
   
   assign inv = BITVAL ^ CRC[9];                   // XOR required?
   
   always @(posedge BITSTRB or posedge CLEAR) begin
      if (CLEAR) begin
         CRC = 0;                                  // Init before calculation
         end
      else begin
         CRC[9] = CRC[8] ^ inv;
         CRC[8] = CRC[7];
         CRC[7] = CRC[6];
         CRC[6] = CRC[5];
         CRC[5] = CRC[4] ^ inv;
         CRC[4] = CRC[3] ^ inv;
         CRC[3] = CRC[2];
         CRC[2] = CRC[1];
         CRC[1] = CRC[0] ^ inv;
         CRC[0] = inv;
         end
      end
   
endmodule




A simple C implementation of the above polynom is shown in the following code. Again, you can directly copy the source snippet to your code (distributed under LGPL):


// ==========================================================================
// CRC Generation Unit - Linear Feedback Shift Register implementation
// (c) Kay Gorontzi, GHSi.de, distributed under the terms of LGPL
// ==========================================================================
char *MakeCRC(char *BitString)
   {
   static char Res[11];                                 // CRC Result
   char CRC[10];
   int  i;
   char DoInvert;
   
   for (i=0; i<10; ++i)  CRC[i] = 0;                    // Init before calculation
   
   for (i=0; i<strlen(BitString); ++i)
      {
      DoInvert = ('1'==BitString[i]) ^ CRC[9];         // XOR required?

      CRC[9] = CRC[8] ^ DoInvert;
      CRC[8] = CRC[7];
      CRC[7] = CRC[6];
      CRC[6] = CRC[5];
      CRC[5] = CRC[4] ^ DoInvert;
      CRC[4] = CRC[3] ^ DoInvert;
      CRC[3] = CRC[2];
      CRC[2] = CRC[1];
      CRC[1] = CRC[0] ^ DoInvert;
      CRC[0] = DoInvert;
      }
      
   for (i=0; i<10; ++i)  Res[9-i] = CRC[i] ? '1' : '0'; // Convert binary to ASCII
   Res[10] = 0;                                         // Set string terminator

   return(Res);
   }

// A simple test driver:

#include <stdio.h>

int main()
   {
   char *Data, *Result;                                       // Declare two strings

   Data = "1101000101000111";
   Result = MakeCRC(Data);                                    // Calculate CRC
   
   printf("CRC of [%s] is [%s] with P=[11000110011]\n", Data, Result);
   
   return(0);
   }



Of course, the software is provided here 'as is' with no expressed or implied warranties at all.

Do you consider this page somewhat useful? Please drop me a note via contact.