/// 获取校验和,ASCII编码
/// </summary>
/// <param name="s"枣手></param>
/// <param checkSum="s"></param>
#region 获取校验和,ASCII编码
/// <summary>
/// 获颂首取校验和,ASCII编码
/// </summary>
/// <param name="s"></param>
/// <param checkSum="s"></param>
private bool GetCheckSum( string s , out string checkSum )
{
checkSum = ""
if ( 0 == s.Length )
return false
int sIndex = s.IndexOf( '$' ) + 1
int eIndex = s.IndexOf( "**" )
string str = ""
if ( sIndex <1 || eIndex <1 )
str = s
else
str = s.Substring( sIndex , eIndex - sIndex )
byte [] cs = Encoding.ASCII.GetBytes( str )
for ( int i = 0 i <cs.Length - 1 i++ )
{
cs [i + 1] = (byte) ( cs [i] ^ cs [i + 1] )
}
checkSum = cs [cs.Length - 1].ToString( "x2" ).ToUpper()
//checkSum = Convert.ToString( cs [cs.Length - 1] , 16 ).ToUpper()
return true
}
#include <stdio.h>#include <烂宏stdlib.h>
int main()
{
char ch
signed char checksum=-1
while((ch=getchar())!=EOF)
{
putchar(ch)
checksum+=ch
if(ch=='\n')
{
printf("%d\饥蠢册档没n",checksum)
checksum=-1
}
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)