Pouvez vous me dire , svp , si vous voyer une erreur dans ce code?


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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
 
#include <math.h>
 
unsigned char bit_test(unsigned char,unsigned int);
unsigned char bit_set(unsigned char,unsigned int);
unsigned char bit_clear(unsigned char,unsigned int);
unsigned char generate_8bit_crc(unsigned char*,unsigned int,unsigned char);
 
 
unsigned char generate_8bit_crc(unsigned char* data,unsigned int length, unsigned char pattern)
{
   unsigned char   *current_data;
   unsigned char   crc_byte;
   unsigned int   byte_counter;
   unsigned int   bit_counter;
 
   current_data = data;
   crc_byte = *current_data++;
 
   for(byte_counter=0; byte_counter < (length-1); byte_counter++)
   {
      for(bit_counter=0; bit_counter < 8; bit_counter++)
      {
         if(bit_test(crc_byte,7)==0)
         {
            crc_byte <<= 1;
            if(bit_test(*current_data, 7 - bit_counter)==128)
            {crc_byte=bit_set(crc_byte,0);}
            else
            {crc_byte=bit_clear(crc_byte,0); }
            continue;
         }
         crc_byte <<= 1;
         if(bit_test(*current_data, 7 - bit_counter)==128)
         {
           crc_byte=bit_set(crc_byte,0);
         }
         else
         {
         crc_byte=bit_clear(crc_byte,0);
         }
      crc_byte ^= pattern;
      }
   current_data++;
   }
   for(bit_counter=0; bit_counter < 8; bit_counter++)
   {
      if(bit_test(crc_byte,7)==0)
      {
         crc_byte <<= 1;
         continue;
      }
      crc_byte <<= 1;
      crc_byte ^= pattern;
   }
   return crc_byte;
}
 
unsigned char bit_test(unsigned char X,unsigned int Y)
{
   unsigned char RES;
   unsigned char Z=pow(2,Y);
   RES=X & Z;
   return (RES);
}
 
unsigned char bit_set(unsigned char X,unsigned int Y)
{
 
   unsigned char Z=pow(2,Y);
   return (X | Z);
}
 
unsigned char bit_clear(unsigned char X,unsigned int Y)
{
   unsigned char Z=pow(2,Y);
   return (X & (~Z));
}

Merci d avance de votre aide