Bonjour à tous,

J'ai besoin de comprendre le calcul fait par cette fonction (issue d'une doc) afin de le faire à la main.
N'étant pas une élite des symboles C, je demande votre aide afin de transcrire ça en math.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
This ‘C’ code segment and data table illustrates how the CRC is calculated.
 
typedef unsigned int WORD;
typedef unsigned char BYTE;
typedef union{
	WORD w;
	struct{
		BYTE lo, hi;
	} b;
} BYTEWORD;
WORD ComputeCRC16(char *msg, int len){
	BYTEWORD chksum;
	unsigned char *msgchk;
	chksum.w = 0xFFFF;
	msgchk = (unsigned char *) msg;
	while (len--){
		chksum.w = chksum.b.hi ^ (ccittrev_tbl[chksum.b.lo ^ *msgchk++]);
	}
	chksum.w = ~chksum.w;
	return(chksum.w);
}
Le CRC est sur 2 bits...
Pour des éventuels tests, voici quelques exemples en hexa:
01 02 00, doit retourner: 9F DE
08 02 01 4F 00, doit retourner: 76 5E
08 02 01 23 00, doit retourner: 76 73
07 02 00, doit retourner: 9E 3E
05 02 00, doit retourner: 5E 9F

Merci d'avance.