Algorithm title: UVA 128 Software CRC (number theory conversion)

Source: Internet
Author: User
Tags numeric value

Software CRC

You are work for a company which uses lots of personal computers. Your boss, Dr Penny Pincher, has wanted to link the computers together for some time but has been unwilling to spend any m Oney on the Ethernet boards for you have recommended. You, unwittingly, have pointed out of this each of the PCs has come to the vendor with a asynchronous port at no ex Tra cost. Dr Pincher, of course, recognizes her opportunity and assigns your task of writing the software necessary to allow Comm Unication between PCs.

' ve read a bit about communications and know that every transmission are subject to error and that typical solution To this problem be to append some error checking information to the "End of". This information allows the receiving program to detect when a transmission error has occurred (in most). So, from the go to the library, borrow the "biggest book" on communications for you can find and spend the your weekend (unpaid overt IME) reading about error checking.

Finally You decide so CRC (cyclic redundancy check) is the best error checking for your situation and write a note to Dr Pincher detailing the proposed error checking mechanism noted.

CRC Generation

The message to was transmitted is viewed as a long positive binary number. The the message is treated as the most significant byte of the binary number. The second byte is the next most significant, etc. This binary number is called ' m ' (for message). Instead of transmitting ' m ' ' you'll transmit a message, ' M2 ', consisting of ' ' m ' followed by a two-byte CRC value.

The CRC value is chosen so "m2" when divided by a certain 16-bit value ' g ' leaves a remainder of 0. This is makes it easy for the receiving program to determine whether the message has been corrupted by transmission errors. It simply divides any message received by ' G '. If the remainder of the division is zero, it's assumed that no error has occurred.

You are notice that most of the suggested values of "G" in the book are odd, but don ' t Lect the value 34943 for ' G ' (the generator value).

Input and Output

You are are to devise a algorithm for calculating the CRC value corresponding to any message that might is sent. To the test this algorithm you would write a program which reads lines (each line being all characters up to, but not including The end of line character) as input, and for each line calculates the CRC value for the "message contained in", an D writes the numeric value of the CRC bytes (in hexadecimal notation) on a output line. Each input line would contain no more than 1024 ASCII characters. The "input is terminated by a" that contains a # in column 1. Note This each CRC printed should is in the range 0 to 34942 (decimal).

Sample Input

This is a test

A

#

Sample Output

FD

00 00

0C 86

Related Article

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.