/*************************************************
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);
    }
}

最新文章

  1. old header
  2. HDU 4292 Food 最大流
  3. Android绘图之渐隐动画
  4. Hadoop2.6.0(2.4~2.7)完全分布式搭建-入门向 新手向 详细流程
  5. zoj 2686 Cycle Game 博弈论
  6. 遇见NodeJS:JavaScript的贵人
  7. 警告:Pointer is missing a nullability type specifier (__nonnull or __nullable)
  8. 将分页功能从JSP页面中独立出来
  9. 各浏览器对 window.open() 的窗口特征 sFeatures 参数支持程度存在差异
  10. Unbound classpath container: &amp;#39;JRE System Library [jdk17060]&amp;#39; in project ***
  11. js 数组 remove
  12. SQL学习 DECODE
  13. CentOS7 使用systemctl来管理服务
  14. TSMBIOS
  15. 编译安装Python3
  16. 解决Everything1.4版本预览时不支持自定义后缀的问题
  17. Node 开启
  18. cocos环境配置 -cocos2dx 入门
  19. vue组件中this和$el指向
  20. tools-eclipse-004-UML图安装

热门文章

  1. SpringMVC序列化Long转成String
  2. MyBatis学习系列三——结合Spring
  3. 破解Demo
  4. HTML5 CSS3简要教程
  5. Thinking about think-time functions
  6. Outlook 2007无法打开链接&quot;由于本机的限制 该操作已被取消&quot;
  7. MongoDb Replica Set中使用的地址
  8. LogStash 中字段的排除和数据的排除
  9. 使用java8的lambda将list转为map(转)
  10. android属性