依次得出16进制的和public String makeChecksum(String hexdata) { if (hexdata == null || hexdata.equals("")) { return "00"; } hexdata = hexdata.replaceAll(" ", ""); int total = 0; int len = hexdata.length(); if (len % 2 != 0) { return "00"; } int num = 0; while (num < len) { String s = hexdata.substring(num, num + 2); total += Integer.parseInt(s, 16); num = num + 2; } return hexInt(total); } private String hexInt(int total) { int a = total / 256; int b = total % 256; if (a > 255) { return hexInt(a) + format(b); } return format(a) + format(b); } private String format(int hex) { String hexa = Integer.toHexString(hex); int len = hexa.length(); if (len < 2) { hexa = "0" + hexa; } return hexa; }
java 16进制求和
最新推荐文章于 2024-07-10 03:41:14 发布