Home    | Products    | Downloads    | Purchase    | Support   

 Products

 Paint Express

 HashCalc

 FSUM

 QuickHash Library

 FastCRC Library

    Download

    Purchase

    Samples

    License Agreement

    Related Links

    F.A.Q.

    Overview

 Company

 About Us

 Contact Us

 Miscellaneous

 Affiliate Program

 Site Map

SlavaSoft FastCRC Library Samples
Sample #1 (C++ Interface)  

All

Previous Next


The following sample demonstrates how to use the CFastCRC16 class to calculate the CRC16 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 = CFastCRC16::Calculate( buff );

       //Get and show the hexadecimal representation of the checksum

       SL_FCRC_ConvertToHex16( checksumhex, checksum, 0 );

       cout << checksumhex;

       //Instantiate a CFastCRC16 object

       CFastCRC16 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;
}
 
  Copyright SlavaSoft Inc. All rights reserved.