128-software CRC // return the remainder of a Large Number

Source: Internet
Author: User

The question is hard to understand, but it is very simple. It is to give a 256 hexadecimal number and take the remainder.

Below isCode:

# Include <iostream> # include <cstdio> # include <cstring> using namespace STD; const int q = 34943; const int d = 256; char M [1025]; char ans [5]; int main () {While (gets (M) {If (M [0] = '#') break; int lenstring = strlen (m); If (lenstring = 0) {printf ("00 00 \ n"); continue;} // get remainder long Re = 0; for (INT I = 0; I <lenstring; I ++) {Re = (Re * D + M [I]) % Q ;}// there are Aother bit. re = Re * D * d % Q; // If Re is a bit big, then re * D may overflow! So re shoshould be long int CRC = re? Q-Re: 0; sprintf (ANS, "% 04x", CRC); // turn decimal into hexadecimal printf ("% C \ n ", ans [0], ANS [1], ANS [2], ANS [3]);} return 0 ;}
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.