// 将Src整数,转换为BCD码,BCD码长度为len
uchar* int2BCD(int src, uchar* dst, int len)
{
for (int i=len-1; i>=0; i--)
{
dst[i]=char2BCD(src%100);
src = src/100;
};
return dst;
}
// 将一个字符的数字,转换为BCD码
uchar char2BCD(uchar c)
{
uchar ret(0);
ret = c%10;
c = c/10;
ret |= (c%10)<<4;
return ret;
}
//eg: 2个BCD码 src = 0x20 0x18 ===> 转换后 int = 2018
// 将BCD码,转换为整数,BCD码长度为len
int BCD2int(uchar* src, int len)
{
int ret(0);
for (int i=0; i<len; i++)
{
ret *= 100;
ret += ((src[i]&0xf0)>>4)*10+(src[i]&0x0f);
};
return ret;
}
inline void str2char(QString str,char* des)
{
for (int i = 0; i < str.length(); ++i) {
des[i] = str.at(i).toLatin1() - 0x30;
}
}
inline void SaveToFile(const QString &fname, const QString &csArray)
{
if ( !fname.isEmpty())
{
QFile file(fname);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QTextStream ts(&file);
ts.setCodec("UTF-8");
ts << csArray;
file.close();
}
}