The CRC check function is encapsulated in the class, and the CRC is verified by the console parameter (relative path of the file).
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.IO;4 usingSystem.Linq;5 usingSystem.Text;6 usingSystem.Threading.Tasks;7 8 namespaceCRC9 {Ten class Program One { A Static voidMain (string[] args) - { -UInt32 LASTCRC =0x0000; the Try - { -FileStream filebytes =NewFileStream (args[0], FileMode.Open, FileAccess.Read); -BinaryReader Binaryfile =NewBinaryReader (filebytes); + while(true) - { +LASTCRC =calacrc.crccalculating (Binaryfile.readbyte ()); A } at filebytes.close (); - } - Catch(endofstreamexception o) - { -LASTCRC =calacrc.crcupside (LASTCRC); - } in Console.WriteLine (LASTCRC); - } to } + classCALACRC - { the Public StaticUInt32 crccalculating (UInt32 crcbyte) { *UInt32 Crcregister =0xFFFF; $Crcregister = (crcbyte ^crcregister);Panax NotoginsengCrcregister = Crcregister >>1; - inti =1; the + for(; I <=8; i++) A { the if(Crcregister%2==0) + { -Crcregister = crcregister ^0xa001; $i--; $ } - Else -Crcregister = Crcregister >>1; the } - returnCrcregister;Wuyi } the - Public StaticUInt32 crcupside (UInt32 crcregister) Wu { -UInt32 crcdata = crcregister% the; AboutCrcregister = Crcregister/ the; $Crcdata = Crcdata * the; -Crcregister = Crcregister +Crcdata; - returnCrcregister; - } A } +}
Using the FileStream class to read the file, the external parameters go in to get the relative path of the checksum file, and output the result.
There are 16 prototype data prototypes for testing in Test.txt:
Invoking a program in the console
Next, use the form program to invoke the validation check algorithm.
CRC Check Program 2: Multibyte the document as a data source for CRC verification by command prompt, output check code