时间:2023-01-28 10:34:06 | 栏目:.NET代码 | 点击:次
private Byte GetCheckSum(Byte[] bytes) { Byte checksum = 0x00; foreach (byte bt in bytes) { checksum ^= bt; } return checksum; }
private static string CheckSum(string message) { char[] chars = message.ToCharArray(); int checksum = 0; for (int i = 0; i < chars.Length; i++) { checksum += (int)chars[i]; } checksum = (~checksum & 0xFFFF) + 0x0001; return Convert.ToString(checksum, 16).ToUpper(); }
例如:
字符串“1234567890” 的 CheckSum 为:“FDF3”