Java Cumulative and checksum implementation mode 16 (recommended) _java

Source: Internet
Author: User

A string is known, and the 16 sum of the string is given, and a string and a checksum code are known, and the checksum additive is valid, but not much. directly on the code

public static string Makechecksum (String data) {
 if (data = null | | data.equals ("")) {return
  "";
 }
 int total = 0;
 int len = Data.length ();
 int num = 0;
 while (Num < len) {
  String s = data.substring (num, num + 2);
  System.out.println (s);
  Total + = Integer.parseint (s,);
  num = num + 2;
 }
 /**
  * With 256 of the maximum is 255, that is, 16-in
  FF
 /int mod = total% 256;
 String hex = integer.tohexstring (mod);
 Len = Hex.length ();
 If the length of the check bit is not enough, fill 0, here is the two-digit checksum
 if (Len < 2) {
  hex = "0" + hex;
 }
 return hex;
 }

The above Java cumulative and verify implementation of the way 16 (recommended) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.

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.