My C # Introductory Road _day4

Source: Internet
Author: User

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

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.