FastCRC Library C++ Interface

The following sample demonstrates how to use the CFastCRC16C class to calculate the CRC16C checksum for a string.

#include <iostream>
#include <FastCRC.h>

using namespace std;
using namespace FastCRC;

int main()
{
    char buff[ 256 ]; 

    unsigned long checksum;
    char checksumhex[ SLC_FCRC_MAXHEXSIZE ]; //0 terminated

    do
    {
        //Get the string from the user

        cout << "\nEnter a string: ";
        cin.getline( buff, 256, '\n' );

        cout << "\nChecksum for \"" << buff <<"\":";

        //Calculate the checksum using Calculate

        cout << "\nCalculated using Calculate:           ";

        checksum = CFastCRC16C::Calculate( buff );
	//Get and show the hexadecimal representation of the checksum
	SL_FCRC_ConvertToHex16( checksumhex, checksum, 0 );

        cout << checksumhex;

        //Instantiate a CFastCRC16C object

        CFastCRC16C crcobj;

        //Calculate the checksum using Update and Final

        cout << "\nCalculated using Update and FinalHex: ";

        crcobj.Update( buff );
        checksum = crcobj.Final(); // Final reinitializes the crcobj object for the next use
	//Get and show the hexadecimal representation of the checksum
	SL_FCRC_ConvertToHex16( checksumhex, checksum, 0 );
        cout << checksumhex;

        //Continue?

        cout << "\nContinue (Y/N)?";
        cin.getline( buff, 256 );

    } while ( *buff == 'y' || *buff == 'Y' );

    return 0;
}

 


 

 

Send Feedback to SlavaSoft Inc. Tell a friend about FastCRC Library