java cumulative and checksum implementation is recommended in hexadecimal of
- 2020-05-17 05:23:48
- OfStack
Given 1 string, find the hexadecimal sum of the string, given 1 string and the checksum code, whether the checksum and the sum are legal, say nothing more 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, 16);
num = num + 2;
}
/**
* with 256 The largest of these is 255 , i.e., 16 Into the system FF
*/
int mod = total % 256;
String hex = Integer.toHexString(mod);
len = hex.length();
// If the length of the check bit is not enough, make up 0, This is a two-digit check
if (len < 2) {
hex = "0" + hex;
}
return hex;
}