On 11 Dec 2017 at 21:51, Isaac M. Bavaresco wrote: > Those checksums seem to be very biased and probably are not good for > ensuring data integrity. > > Why not using CRC? CRC8 is probably much stronger than any checksum and > easy to implement. It is computationally light too. Right you are Isaac. There was some effort required in getting the CRC function implemented corr= ectly, (basically choosing from existing code examples, then testing to make sure = it works as expected), but the performance gain looks really impressive. Found this CRC code I had used before, taken from an example in an RFID tag reader manual, apparently CCITT-CRC-8 polygon x^8+x^4+x^3+x^2+1. char CalcCRC8(char CRC, char byte){ unsigned char count; for (count =3D 0; count < 8; ++count){ if (((CRC & 0x01) ^ (byte & 0x01)) !=3D 0){ CRC ^=3D 0x70; CRC >>=3D 1; CRC |=3D 0x80; } else{ CRC >>=3D 1; CRC &=3D 0x7F; } byte >>=3D 1; } return CRC; } >From the C code Jason sent through (thanks again) I modified it to produce= results for the basic 8 bit checksum and the 8 bit CRC function above. To recap, th= ere are 6 digits of 10 symbols (0x3C, 0x4B, 0x5A, 0x69, 0x78, 0x87, 0x96, 0xA5, 0xB= 4, 0xC3), representing all 10^6 (1 million) possible codes of decimal numbers = from 000000 - 999999. Below is a list of all the 8 bit checksum/CRC values in Hex (first coulmn, = 256 of them), then the number of times (decimal) each appears for a simple checksu= m (second column) and CRC (third column). The performance of CRC is exception= al... all 256 possible results are represented, with near perfect distribution (1= /256 x 1000000 =3D 3906). For my previously mentioned requirement of the check value not equalling 0x= FF, I think I can live with testing for and replacing that occurence with a diffe= rent code. 0x00: 0 3906 0x01: 0 3911 0x02: 0 3906 0x03: 0 3911 0x04: 0 3911 0x05: 0 3906 0x06: 0 3911 0x07: 0 3906 0x08: 0 3904 0x09: 0 3904 0x0A: 0 3904 0x0B: 2002 3904 0x0C: 54747 3904 0x0D: 4332 3904 0x0E: 0 3904 0x0F: 0 3904 0x10: 0 3906 0x11: 0 3911 0x12: 0 3906 0x13: 0 3911 0x14: 0 3911 0x15: 0 3906 0x16: 0 3911 0x17: 0 3906 0x18: 0 3904 0x19: 0 3904 0x1A: 1287 3904 0x1B: 53262 3904 0x1C: 6062 3904 0x1D: 0 3904 0x1E: 0 3904 0x1F: 0 3904 0x20: 0 3911 0x21: 0 3906 0x22: 0 3911 0x23: 0 3906 0x24: 0 3906 0x25: 0 3911 0x26: 0 3906 0x27: 0 3911 0x28: 0 3904 0x29: 792 3904 0x2A: 50877 3904 0x2B: 8232 3904 0x2C: 0 3904 0x2D: 0 3904 0x2E: 0 3904 0x2F: 0 3904 0x30: 0 3911 0x31: 0 3906 0x32: 0 3911 0x33: 0 3906 0x34: 0 3906 0x35: 0 3911 0x36: 0 3906 0x37: 0 3911 0x38: 462 3904 0x39: 47712 3904 0x3A: 10872 3904 0x3B: 0 3904 0x3C: 0 3904 0x3D: 0 3904 0x3E: 0 3904 0x3F: 0 3904 0x40: 0 3911 0x41: 0 3906 0x42: 0 3911 0x43: 0 3906 0x44: 0 3906 0x45: 0 3911 0x46: 0 3906 0x47: 252 3911 0x48: 43917 3904 0x49: 13992 3904 0x4A: 0 3904 0x4B: 0 3904 0x4C: 0 3904 0x4D: 0 3904 0x4E: 0 3904 0x4F: 0 3904 0x50: 0 3911 0x51: 0 3906 0x52: 0 3911 0x53: 0 3906 0x54: 0 3906 0x55: 0 3911 0x56: 126 3906 0x57: 39662 3911 0x58: 17577 3904 0x59: 0 3904 0x5A: 0 3904 0x5B: 0 3904 0x5C: 0 3904 0x5D: 0 3904 0x5E: 0 3904 0x5F: 0 3904 0x60: 0 3906 0x61: 0 3911 0x62: 0 3906 0x63: 0 3911 0x64: 0 3911 0x65: 56 3906 0x66: 35127 3911 0x67: 21582 3906 0x68: 1 3904 0x69: 0 3904 0x6A: 0 3904 0x6B: 0 3904 0x6C: 0 3904 0x6D: 0 3904 0x6E: 0 3904 0x6F: 0 3904 0x70: 0 3906 0x71: 0 3911 0x72: 0 3906 0x73: 0 3911 0x74: 21 3911 0x75: 30492 3906 0x76: 25927 3911 0x77: 6 3906 0x78: 0 3904 0x79: 0 3904 0x7A: 0 3904 0x7B: 0 3904 0x7C: 0 3904 0x7D: 0 3904 0x7E: 0 3904 0x7F: 0 3904 0x80: 0 3906 0x81: 0 3911 0x82: 0 3906 0x83: 6 3911 0x84: 25927 3911 0x85: 30492 3906 0x86: 21 3911 0x87: 0 3906 0x88: 0 3904 0x89: 0 3904 0x8A: 0 3904 0x8B: 0 3904 0x8C: 0 3904 0x8D: 0 3904 0x8E: 0 3904 0x8F: 0 3904 0x90: 0 3906 0x91: 0 3911 0x92: 1 3906 0x93: 21582 3911 0x94: 35127 3911 0x95: 56 3906 0x96: 0 3911 0x97: 0 3906 0x98: 0 3904 0x99: 0 3904 0x9A: 0 3904 0x9B: 0 3904 0x9C: 0 3904 0x9D: 0 3904 0x9E: 0 3904 0x9F: 0 3904 0xA0: 0 3911 0xA1: 0 3906 0xA2: 17577 3911 0xA3: 39662 3906 0xA4: 126 3906 0xA5: 0 3911 0xA6: 0 3906 0xA7: 0 3911 0xA8: 0 3904 0xA9: 0 3904 0xAA: 0 3904 0xAB: 0 3904 0xAC: 0 3904 0xAD: 0 3904 0xAE: 0 3904 0xAF: 0 3904 0xB0: 0 3911 0xB1: 13992 3906 0xB2: 43917 3911 0xB3: 252 3906 0xB4: 0 3906 0xB5: 0 3911 0xB6: 0 3906 0xB7: 0 3911 0xB8: 0 3904 0xB9: 0 3904 0xBA: 0 3904 0xBB: 0 3904 0xBC: 0 3904 0xBD: 0 3904 0xBE: 0 3904 0xBF: 0 3904 0xC0: 10872 3911 0xC1: 47712 3906 0xC2: 462 3911 0xC3: 0 3906 0xC4: 0 3906 0xC5: 0 3911 0xC6: 0 3906 0xC7: 0 3911 0xC8: 0 3904 0xC9: 0 3904 0xCA: 0 3904 0xCB: 0 3904 0xCC: 0 3904 0xCD: 0 3904 0xCE: 0 3904 0xCF: 8232 3904 0xD0: 50877 3911 0xD1: 792 3906 0xD2: 0 3911 0xD3: 0 3906 0xD4: 0 3906 0xD5: 0 3911 0xD6: 0 3906 0xD7: 0 3911 0xD8: 0 3904 0xD9: 0 3904 0xDA: 0 3904 0xDB: 0 3904 0xDC: 0 3904 0xDD: 0 3904 0xDE: 6062 3904 0xDF: 53262 3904 0xE0: 1287 3906 0xE1: 0 3911 0xE2: 0 3906 0xE3: 0 3911 0xE4: 0 3911 0xE5: 0 3906 0xE6: 0 3911 0xE7: 0 3906 0xE8: 0 3904 0xE9: 0 3904 0xEA: 0 3904 0xEB: 0 3904 0xEC: 0 3904 0xED: 4332 3904 0xEE: 54747 3904 0xEF: 2002 3904 0xF0: 0 3906 0xF1: 0 3911 0xF2: 0 3906 0xF3: 0 3911 0xF4: 0 3911 0xF5: 0 3906 0xF6: 0 3911 0xF7: 0 3906 0xF8: 0 3904 0xF9: 0 3904 0xFA: 0 3904 0xFB: 0 3904 0xFC: 2997 3904 0xFD: 55252 3904 0xFE: 2997 3904 0xFF: 0 3904 -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .