CRC_16_CCITT in C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public static ushort doCRC16(byte[] data)
{
	ushort crc = 0xFFFF;
	for (int r = 0; r < data.Length; r++ )
	{
		byte dat = data[r];
		for (int j = 0; j < 8; j++ )
		{
		if (((dat ^ crc) & 0x01) != 0 )
		{
			crc >>= 1;
			crc ^= 0x8008; // CRC_POLYNOM;
		}
		else { crc >= 1; }
		dat >>= 1;
		}
	}
        crc = (ushort)(crc ^ 0xFFFF);
 
   return new byte[] { (byte)(crc >> 8), (byte)(crc & 0x00ff) };
 
}
  • muti
  • del.icio.us
  • Digg
  • Reddit
  • Technorati
  • Twitter

Category: all 8 comments »

8 Responses to “CRC_16_CCITT in C#”

  1. Etum

    Tu fais du C#? hum j’aurai tout vu

  2. septox

    Bon la je prefere ne rien dire !!

  3. Etum

    Lol tu as lom parles

  4. Ti Aya

    Est-ce que je me trompe, ou bien ça aurait été exactement le même code en Java?

  5. septox

    Bon.

    @Etum
    C# ne veut pas toujors automaitquement Microsoft et Windows.
    Il existe aussi le projet Mono

    @TiAya
    Tout a fait, avec la petite difference qu’on pas le type ushort en Java.

  6. Ti Aya

    Ton code me rappelle qu’il y a qq temps, j’ai eu besoin d’une fonction de hashage pour partager un mot de passe commun entre des softs PHP5, C++/Win et C++/Linux. J’ai bien galéré avant de trouver une solution.

  7. mambe nanje churchill

    what is the code trying to do ? with one function and no write up I realy dont follow this article.
    getting data and doing some byte manipulation. but my question is what is it actually doing ?

  8. septox

    all what this function do, is in the function name (doCRC16).
    So waht is CRC16 ?? just ask the big wiki, chief of the indians of pedia in org


Leave a Reply


     

Afrigator