CRC Check Program 2: Through the command prompt multibyte download this document as a data source for CRC check, output check code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.