日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

C#中的checksum計算公式_C#教程

作者:海歌也瘋狂 ? 更新時間: 2022-06-19 編程語言

checksum計算公式

private Byte GetCheckSum(Byte[] bytes)
{
	Byte checksum = 0x00;
 
	foreach (byte bt in bytes)
	{
		checksum ^= bt;
	}
 
	return checksum;
}

生成字符串的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”

原文鏈接:https://blog.csdn.net/qq_31094099/article/details/108848698

欄目分類
最近更新