C#与c之间通信之一校验字

 c# 获取校验字 :

     private static string GetCheckSum(string Message)
      {
          byte initCheck = 0;
          byte[] bs = Encoding.GetEncoding("GB2312").GetBytes(Message);


       

          foreach (byte c in bs)
          {
              initCheck ^= c;
            
          }
          string a = Convert.ToString(initCheck, 16);

          return a;
      }

c++ 则是:

int CProc::GetChksum(const char *strMsg)
{
 int nCk ;
 int nLen = strlen(strMsg);
 nCk = 0;
 for(int i = 0; i < nLen; i++ )
 {
  nCk = nCk ^ strMsg[i];
 }

 return nCk;
}

posted @ 2011-10-31 16:34  glf  阅读(232)  评论(0编辑  收藏  举报