Appendix B

CheckSum Calculation

The checksum of a FIX message is calculated by summing every byte of the message up to but not including the checksum field itself. This checksum is then transformed into a modulo 256 number for transmission and comparison. The checksum is calculated after all encryption is completed, i.e. the message as transmitted between parties is processed.

For transmission, the checksum must be sent as printable characters, so the checksum is transformed into three ASCII digits.

For example, if the checksum has been calculated to be 274 then the modulo 256 value is 22. This value would be transmitted a |10=022| where "10="is the tag for the checksum field.

A sample code fragment to generate the checksum field is as follows:

char *GenerateCheckSum( char *buf, long bufLen )
{
	static char tmpBuf[ 4 ];
	long idx;
	unsigned int cks;

	for( idx = 0L, cks = 0; idx < bufLen; cks += (unsigned int)buf[ idx++ ] );
	sprintf( tmpBuf, "%03d", (unsigned int)( cks % 256 ) );
	return( tmpBuf );	
}