QT 十六进制字符串转化为十六进制编码
/*************************************************
Function: hexStringtoByteArray()
Description: 十六进制字串转化为十六进制编码
Calls: formatString()
Called By:
Input: hex->待转化的十六进制字串
Output: NULL
Return: QByteArray
Others: NULL
*************************************************/
QByteArray Omron::hexStringtoByteArray(QString hex)
{
QByteArray ret;
hex=hex.trimmed();
formatString(hex,2,' ');
QStringList sl=hex.split(" ");
foreach(QString s,sl)
{
if(!s.isEmpty())
ret.append((char)s.toInt(0,16)&0xFF);
}
return ret;
}
/*************************************************
Function: formatString()
Description: 将十六进制字串每字节中间加空格分隔
Calls:
Called By:hexStringtoByteArray()
Input: org->待处理的字串
n->间隔数默认为2
ch->分隔标志,在此取空格
Output: NULL
Return: void
Others: NULL
*************************************************/
void Omron::formatString(QString &org, int n=2, const QChar &ch=QChar(' '))
{
int size= org.size();
int space= qRound(size*1.0/n+0.5)-1;
if(space<=0)
return;
for(int i=0,pos=n;i<space;++i,pos+=(n+1))
{
org.insert(pos,ch);
}
}
最新文章
- old header
- HDU 4292 Food 最大流
- Android绘图之渐隐动画
- Hadoop2.6.0(2.4~2.7)完全分布式搭建-入门向 新手向 详细流程
- zoj 2686 Cycle Game 博弈论
- 遇见NodeJS:JavaScript的贵人
- 警告:Pointer is missing a nullability type specifier (__nonnull or __nullable)
- 将分页功能从JSP页面中独立出来
- 各浏览器对 window.open() 的窗口特征 sFeatures 参数支持程度存在差异
- Unbound classpath container: &;#39;JRE System Library [jdk17060]&;#39; in project ***
- js 数组 remove
- SQL学习 DECODE
- CentOS7 使用systemctl来管理服务
- TSMBIOS
- 编译安装Python3
- 解决Everything1.4版本预览时不支持自定义后缀的问题
- Node 开启
- cocos环境配置 -cocos2dx 入门
- vue组件中this和$el指向
- tools-eclipse-004-UML图安装