//Byte数组转CString
CString Communal::ByteArrayToCString(CByteArray* btArray)
{
CString cs1,str;
cs1.Empty();
int lon = btArray->GetCount();
for (int i = 0;i<lon;i++)
{
unsigned char x = (unsigned char)btArray->GetAt(i);
str.Format("%02x",x);
cs1+=str.MakeUpper();
}
return cs1;
}
//短整型数据转Byte数组
//unsigned char* Communal::int16ToBytes(short int n)
//{
// unsigned char* pBuffer;
// pBuffer = new unsigned char[2];
// int num = n & 0xFFFF;
// pBuffer[0] = (byte)(num >> 8);
// pBuffer[1] = (byte)(num & 0x00FF);
// return pBuffer;
//}
////整型数据转Byte数组
//unsigned char* Communal::int32ToBytes(int n)
//{
// unsigned char* pBuffer;
// pBuffer = new unsigned char[4];
// int num = n ;//& 0xFFFF;
// pBuffer[0] = (byte)(num &0xF000);
// pBuffer[1] = (byte)(num &0x0F00);
// pBuffer[2] = (byte)(num >> 8);
// pBuffer[3] = (byte)(num & 0x00FF);
// return pBuffer;
//}
//Byte数组转整形数据
//int* Communal::ByteHexToDecInt(unsigned char* byteArray,int len)
//{
// int* intArray;
// intArray = new int[len];
// for (int i = 0;i<len;i++)
// {
// intArray[i] = byteArray[i];
// }
// return intArray;
//}
//十六进制数据输入检验
//bool Communal::CheckPutInHex(CString InputStr,int Length)
//{
// int len = InputStr.GetLength();
// CString str;
// bool bUse = true;
// char *buf;
// if (len!=Length)
// {
// bUse = false;
// }
// else
// {
// for(int i = 0;i<Length;i++)
// {
// str = InputStr.Mid(i,1);
// buf = str.GetBuffer();
// if ((*buf<'0'||*buf>'9')&&(*buf<'a'||*buf>'f')&&(*buf<'A'||*buf > 'F'))
// {
// bUse=false;
// }
// str.ReleaseBuffer();
// }
// }
// return bUse;
//}
来源:CSDN
作者:钟_凌
链接:https://blog.csdn.net/u014626607/article/details/101525674