Platforms to show: All Mac Windows Linux Cross-Platform

CRC_32OfStrMBS(s as String) as UInt32

Type Topic Plugin Version macOS Windows Linux iOS Targets
global method Encryption and Hash MBS Util Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Calculates a 32bit Checksum about the provided string.
Example
dim n as Integer
n=CRC_32OfStrMBS("Hello World")
' n is now 1243066710

See the text "About-CRC" for details about this Checksum things.
This function is also available as part of the memoryblock class.

About Checksums:

These functions calculate CRCs over a range of bytes in a MemoryBlock or in a String.

There are three versions of CRC calculation: One for 16 Bit, one for 32 Bit and one for 16 to 64 Bit wide checksums. If you are free to choose, I suggest that you use the 32 Bit version because of its accuracy and performance.

Some background on using checksums/CRCs:
Checksums, such as CRCs, are used to quickly verify that a chunk of data has not been modified somehow without your control. To use it, you'd calculate the checksum (CRC) of your data, then store that checksum value (which only needs 2 to 8 bytes of storage) somewhere. Later, when retrieving your data, you calculate its checksum again and compare its value with the previously stored value. If it does not match, the data got somehow corrupted. If it matches, that it is quite likely, although not 100% sure, that the data is still in its original state.

There are 3 different CRC algorithms available:

  • CRC_CCITT...() as Integer
  • CRC_32...() as Integer
  • CRC_Dillon...(bitWidth as Integer, ...) as String

The CCITT version calculates a rather classic 16 bit CRC. Unless you need that CRC for legacy data, I recomment not to use it, but rather use the CRC_32 version.

CRC_32 is the most common used algorithm for 32 bit wide CRCs. Be aware there are theoretically many other ways to calculate a CRC 32, however.

The Dillon algorithm is a smart routine to calculate CRCs in any width between 16 and 64 bit. This one is only useful if you find that a 32 bit CRC is not sufficient for your needs. If you can live with a plain 32 bit CRC, you should prefer the CRC_32 routines, because they are faster than the Dillon code.

The result, since it can be up to 64 bit in size, cannot be returned in an Integer (they can only hold 32 bit). Instead, the result is returned as a 8 byte value, stored in a 8 byte long string. To get the value of that string, you can copy the string into a MemoryBlock, and then access the parts opf the 8 byte long value there. The demo project shows how to accomplish this.

The CRC code was developed and published by Matthew Dillon. Here's his web page with more information about it:
http://www.backplane.com/diablo/crc64.html

Some examples using this global method:

The items on this page are in the following plugins: MBS Util Plugin.


The biggest plugin in space...