C# 生成字符串的 CheckSumspa
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」code