This blog record is the process of writing CRC check code.
The process is very bumpy, and finally finished the result of the virtual machine collapsed, the program has not, had to re-come ...
The first is the code for the console application.
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 usingSystem.IO;7 8 9 namespaceConsoleApplication1Ten { One class Program A { - StaticInt64 A (intLengthbyte[] data) - { theInt64 crctemp =65535; - intj =0; - intCHR =0; - intCHR1 =0; + for(inty =0; y < length; y++) - { +CHR = (int) Crctemp &255; ACHR = chr ^Data[j]; atCrctemp = crctemp &0xff00; -Crctemp = Crctemp +CHR; - for(inti =0; I <8; i++) - { - if((Crctemp &0x01) ==1) - { inCrctemp = Crctemp >>1; -Crctemp = crctemp ^0xa001; to + } - Else the { *Crctemp = Crctemp >>1; $ }Panax Notoginseng } -J + =1; the } +CHR = (int) Crctemp &0xFF; ACHR1 = (int) Crctemp &0xff00; thecrctemp = Chr <<8| CHR1 >>8; + returncrctemp; - } $ Static voidMain (string[] args) $ { - stringstr; -Console.WriteLine ("input your file please:"); thestr =console.readline (); -FileStream fs =NewFileStream (str, filemode.open);Wuyi byte[] bt =New byte[ +]; the inti =0; -BinaryReader br =NewBinaryReader (FS); Wu while(Br. Peekchar () >=0) - { AboutBt[i] =Br. ReadByte (); $i++; - } - Int64 result; -result =A (i, BT); AConsole.WriteLine ("The result is 0x"+result); + the - $ } the } the}
One of the algorithms is to read a long time of the experimental requirements, but also Baidu has been looking to understand ...
Then the content of the test file "123.txt":
Crccalculation
Finally, the result of the operation:
(PS: The word may be a little bit smaller)
My C # Introductory Road _day4