| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Calculates the checksum for a stream of data using the Adler32 algorithm.
HB_CheckSum( <cString> ) --> nAdler32
The function returns the calculated checksum as a numeric value.
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
| Function | Algorithm | Relative Speed |
|---|---|---|
| HB_CheckSum() | Adler 32 bit | 1.00 |
| HB_CRC32() | CRC 32 bit | 1.46 |
| HB_MD5() | MD5 128 bit | 4.51 |
| See also: | HB_CRC32(), HB_MD5() |
| Category: | Checksum functions , xHarbour extensions |
| Source: | rtl\hbchksum.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// 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
http://www.xHarbour.com