string 类型转换成byte

来源:互联网 发布:淘宝有好货收藏找不到 编辑:程序博客网 时间:2024/06/06 06:49

BYTE StringToByte(LPCTSTR strSrc,int nCount)
{
 int nResult=0;
 CString str(strSrc);
 
 if (str.IsEmpty())
  return nResult;

 for(int i=0;i<nCount;i++)
 {
  int h=str.GetAt(i);
  if(h>=48 && h <=57)
  {
   h=h-48;
  }
  else if(h>=65 && h <=70)
  {
   h=h-55;
  }
  else if(h>=97&&h <=122)
  {
   h=h-87;
  }
  nResult+=(int)pow(16,nCount-(i+1))* h;
 }
 return nResult;
}

原创粉丝点击