Qt:16进制字符串数据转整数数值函数

2023-05-16

//16进制字符串数据转整数数值
int Setting::qStringHexToInt(QString qStringHex)
{
    int transValue = 0;
    int base = 1;
    for(int i = 0; i < qStringHex.length(); i++)
    {
        qDebug("转换的字符是%c",qStringHex.at(i).toLatin1());
        switch (qStringHex.at(i).toLatin1()) {
            case '0':
                break;
            case '1':
                base = 1;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case '2':
                base = 2;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case '3':
                base = 3;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case '4':
                base = 4;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case '5':
                base = 5;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case '6':
                base = 6;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case '7':
                base = 7;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case '8':
                base = 8;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case '9':
                base = 9;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case 'a':
                base = 10;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case 'b':
                base = 11;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case 'c':
                base = 12;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case 'd':
                base = 13;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case 'e':
                base = 14;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case 'f':
                base = 15;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case 'A':
                base = 10;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case 'B':
                base = 11;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case 'C':
                base = 12;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case 'D':
                base = 13;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case 'E':
                base = 14;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            case 'F':
                base = 15;
                for(int j = qStringHex.length()-(i+1); j > 0; j--)
                {
                    base *= 16;
                }
                transValue += base;
                qDebug("此时base=%d, transValue=%d", base,transValue);
                break;
            default:
                break;
        }
    }
    return transValue;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Qt:16进制字符串数据转整数数值函数 的相关文章

  • Qt重定向问题

    概念 在我们使用软件时大多使用release版本 xff0c 这样在使用过程中的调试信息就不会显示出来 xff0c 为了将调试信息打印在界面上或者放在文件中保存起来我们就可以使用重定向的技术 在QT的帮助文档 xff1a qInstallM
  • VSUDP通信

    好久没弄VS的UDP通信了 xff0c 使用方式都忘记的差不多了 今天遇到了正好学习一下 UDP理论 xff1a UDP参考链接 xff1a socket函数 为了执行网络输入输出 xff0c 一个进程必须做的第一件事就是调用socket函
  • sockaddr_in结构体的说明(成员:sin_family、sin_addr、sin_zero)

    sockaddr in是系统封装的一个结构体 xff0c 具体包含了成员变量 xff1a sin family sin addr sin zero 这个结构体被封装在ws2def h中 xff0c 具体的代码如下 xff1a typedef
  • 字节、位与二进制表示

    前言 仅针对JAVA xff0c 总结几个知识点 字节与位 1字节 xff08 byte xff09 61 8位 xff08 bit xff09 每个bit位非0即1 xff0c 即二进制表达中的0或1 xff0c 0001中每个 0 和
  • windows配置tensorflow python object detection 环境

    option 1 pip install lt binary gt pip install upgrade https storage googleapis com tensorflow mac cpu tensorflow 1 12 0
  • 顺序表递增有序,插入元素x后仍递增有序

    思想 xff1a 1 xff09 先找到x元素的插入位置 xff08 顺序表从左到右依次比较 xff0c 若A元素大于x元素 xff0c 那么x元素插入的位置就是A元素所在的位置 xff09 2 xff09 将A元素所在的位置的元素以及它之
  • 猜数游戏,系统想一个数,我们来猜

    span class token macro property span class token directive keyword include span span class token string lt stdio h gt sp
  • 输入多个数(输入-1为结束标志),计算这多个数的平均数

    span class token macro property span class token directive keyword include span span class token string lt stdio h gt sp
  • 计算n的阶乘

    在 include span class token operator lt span stdio span class token punctuation span h span class token operator gt span
  • 判断一个数是否是素数

    span class token macro property span class token directive keyword include span span class token string lt stdio h gt sp
  • HTTP报文是什么

    x1f4e2 x1f4e2 如果说http是因特网的信使 xff0c 那么http报文就是他用来送信的包裹了 1 x1f4da 什么是报文 在度娘的介绍中 x1f4e3 报文 message 是网络中交换与传输的数据单元 xff0c 即站点
  • STM32串口接收数据处理方法

    STM32串口接收数据处理方法 STM32串口接收定长数据处理方法 STM32串口接收定长数据的处理方法非常简单 xff0c 我目前做项目都是用的这个 xff0c 也可用做处理MODBUS协议 xff0c 直接上代码 span class
  • VScode常用命令

    VScode 的常用快捷键和插件 一 VScode 的常用快捷键 1 注释 xff1a a 单行注释 xff1a ctrl 43 k ctrl 43 c 或 ctrl 43 b 取消单行注释 xff1a ctrl 43 k ctrl 43
  • 彻底搞懂线程、进程、多线程、多进程和多任务的关系

    首先 xff0c 从定义开始 xff0c 先看一下教科书上 进程和线程定义 xff1a 进程 xff1a 资源分配的最小单位 线程 xff1a 程序执行的最小单位 心中默念 xff0c 啥啥啥 xff0c 写的这是啥 1 进程 进程是程序执
  • vmware-workstation-and-device-credential-guard-are-not-compatible

    1 off hyper v feature 2 bcdedit set hypervisorlaunchtype off
  • Ubuntu下配置Multipath TCP(MPTCP)By内核下载(一)

    一 MPTCP介绍 多路径TCP xff08 MPTCP xff09 是一种通过修改TCP来实现同时使用多个IP地址 接口方法 xff0c MPTCP向应用程序提供常规的TCP接口 xff0c 同时实际上跨多个子流传播数据 这样做的好处包括
  • 解决Ubuntu20.04插入英伟达计算卡后无法开机问题-Ubuntu双显卡切换

    解决Ubuntu20 04插入英伟达计算卡后无法开机问题 Ubuntu双显卡切换 问题详述问题分析问题解决 ubuntu双显卡切换 问题详述 本人新配了一台个人使用的机器学习服务器 对环境配置可能有影响的硬件如下 xff1a 华硕B660M
  • python PyQt5使用QT designer不显示问题

    初学Pyqt5记录走过 的坑 xff01 1 窗口自适应 xff1a 窗口自适应我的理解就是使用栅格布局 xff0c 调整后会根据窗口大小调整比例 先把自己需要的截面放在UI上 xff0c 然后使用栅格布局即按Ctrl 43 r即可预览 x
  • opencv跑yolo报错Failed to parse NetParameter file

    64 TOC cv2 error OpenCV 3 4 5 opencv 3 4 5 modules dnn src darknet darknet importer cpp 214 error 212 Parsing error Fail

随机推荐

  • Java自学

    JAVA自学 一 需要掌握的知识点二 资源中心 教程 练习 三 工作要求 图片 一 需要掌握的知识点 java基础 xff08 多线程 IO xff08 nio xff0c bio xff0c aio xff09 xff09 各种数据结构
  • python解析DataMatrix Code二维码

    span class token comment 安装 span span class token triple quoted string string 39 39 39 sudo apt get install libdmtx0a pi
  • SpringBoot中使用自定义异常Exception

    记录一下SpringBoot中使用自定义异常操作方法 代码如下 创建ServiceException class span class token keyword public span span class token keyword c
  • kafka的安装与使用(一)

    kafka的安装与使用 xff08 一 xff09 最近接触消息中间件 xff0c 把使用过程中记录一下 xff01 1 下载与安装 任何文档都要以官方文档为准 xff0c 英文多看两眼你会发现比上次更加熟悉了 xffe3 xffe3 xf
  • 【GITEE】解决 Push rejected

    问题背景 xff1a 更新了台式电脑后 xff0c 从gitlee上拉了代码 xff0c 重新push后就一直报错 xff1a Push single to origin single was rejected by remote 问题解决
  • 一小时学会Python3爬虫基础(二)基础语法 输入输出 关键字 注释

    目录 前言集成环境 编辑器基本语法缩进换行标识符关键字注释输入 输出总结 前言 python作为一门编程语言 xff0c 也跟其他语言一样有自己的逻辑语法 xff0c 那什么是语法 xff1f 跟人一样每个人都有自己说话一套方法 集成环境
  • windows 生成self-sign证书

    打开powershell 管理员身份运行 New SelfSignedCertificate CertStoreLocation Cert LocalMachine My DnsName 34 mysite local 34 Friendl
  • 一小时学会Python3爬虫基础(四)完整解析格式化输出和数据类型转换

    目录 前言格式化输出格式化符号 s格式化函数format格式化表示 f string 转义符和结束符 n意思就是 换行 new line t 叫做水平制表符 tab xff0c r 是回车符carriage return结束符 数据类型转换
  • 一小时学会Python3爬虫基础(七)高级数据的全部操作:字典

    目录 前言字典1 字典格式2 创建有效字典2 创建空字典3 字典类型转换 字典增加和修改1 增加2 修改 字典查找1 key键查找2 get 3 keys 4 values 5 items 字典循环遍历1 遍历字典的key值2 遍历字典的v
  • Python处理异常代码的基本操作,原来都大同小异!

    目录 什么是异常 xff1f 如何捕获异常 xff1f 1 异常的写法2 捕获指定异常3 捕获多个异常4 捕获异常的描述5 捕获所有异常6 异常的else7 finally8 自定义异常模块9 异常传递思路 总结 什么是异常 xff1f 简
  • python的模块与包的关系

    模块和包的概念 python中的模块 xff0c 其实就是一个python的文件 xff0c 包含了很多类和函数 xff0c 基本上都是可以向外调用的 xff0c 或者整个文件都用来处理某个操作 xff0c 我们使用库和框架就是由模块和包构
  • 一小时学会Python基础练习的十四个练手题

    目录 1到100的加法搬家具办公室人员分配猜拳游戏乘公交车吃苹果九九乘法表烤地瓜奇偶100内相加三角形正方形文件备份学员管理系统 xff08 函数版 xff09 学员管理系统 xff08 面向对象版 xff09 mainmangerSyst
  • ROS Topic (话题通信总结)

    拿到一个功能包 xff0c 先运行一下 xff08 以turtlesim为例子 xff09 xff1a rusrun turtlesim turtlesim node 然后使用 rqt graph 和rostopic list 大致了解有哪
  • vector函数用法

    一维 基本用法 xff1a 1 头文件 include lt vector gt 2 创建vector对象 xff0c vector lt int gt vec 3 尾部插入数字 xff1a vec push back a 4 使用下标访问
  • Jetson nano串口的使用——UART

    UART串口使用两条杜邦线就可以实现数据发送和接收 xff0c 可以很方便的与其他扩展进行数据连接 xff0c 比如微雪的L76X GPS HAT就可以直接连接40Pin的GPIO接口通过UART串口进行数据传递 接下来具体说明Jetson
  • Python中[-1]、[:-1]、[::-1]、[n::-1]、[:,:,0]、[…,0]、[…,::-1] 的理解

    在python中会出现 1 1 1 n 1 0 0 1 xff0c 他们分别是什么意思呢 xff0c 这里就来详尽的说一下 xff1a 下面的a 61 1 2 3 4 5 1 xff1a 列表最后一项 1 xff1a 从第一项到最后一项 原
  • 贴片电阻字码阻值对照表

  • 使用sphinx生成python项目文档

    1 pip install sphinx 2 sphinx quickstart 3 修改 conf py import os import sys sys path insert 0 os path abspath 39 39 确保mod
  • 免费商用字体有哪些

    免费商用字体有哪些 一 思源字体 xff0c 可以免费商用的有 思源黑体 xff0c 思源宋体 xff0c 思源柔黑体 二 方正字体 xff0c 方正类字体可以免费商用的有 xff1a 方正仿宋 xff08 简 xff0c 繁 xff09
  • Qt:16进制字符串数据转整数数值函数

    span class token comment 16进制字符串数据转整数数值 span span class token keyword int span Setting span class token operator span sp