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) }; }
Category: all 8 comments »






July 10th, 2008 at 08:08
Tu fais du C#? hum j’aurai tout vu
July 10th, 2008 at 13:37
Bon la je prefere ne rien dire !!
July 10th, 2008 at 17:09
Lol tu as lom parles
July 13th, 2008 at 20:42
Est-ce que je me trompe, ou bien ça aurait été exactement le même code en Java?
July 13th, 2008 at 21:17
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.
July 14th, 2008 at 10:16
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.
July 14th, 2008 at 10:46
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 ?
July 14th, 2008 at 11:42
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