xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HB_CheckSum()

Calculates the checksum for a stream of data using the Adler32 algorithm.

Syntax

HB_CheckSum( <cString> ) --> nAdler32

Arguments

<cString>
This is a character string to calulate the checksum for.

Return

The function returns the calculated checksum as a numeric value.

Description

HB_CheckSum() implements the Adler32 algorithm for calculating the checksum of a character string. This algorithm computes faster than the algorithm of the HB_CRC32() function, but is less reliable, especially for short data streams. The following table compares the speed of checksum algorithms available in xHarbour

Algorithm comparison
FunctionAlgorithmRelative Speed
HB_CheckSum()Adler 32 bit1.00
HB_CRC32()CRC 32 bit1.46
HB_MD5()MD5 128 bit4.51

Info

See also:HB_CRC32(), HB_MD5()
Category: Checksum functions , xHarbour extensions
Source:rtl\hbchksum.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example calculates the checksum for two character
// strings. Note that if the example is compiled, it will
// display a different checksum for cString2 than shown in
// the example. The result changes the checksum of the file
// "Checksum.prg"

   PROCEDURE Main
      LOCAL cString1 := "Hello world"
      LOCAL cString2 := Memoread( "Checksum.prg" )

      ? HB_CheckSum( cString1 )   // result:  413140028.00

      ? HB_CheckSum( cString2 )   // result: 1460748119.00

   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe