ASCII码值转化十六进制,十进制数;十六进制字符值转十进制,ASCII码值;

**用字符表示的十六进制值转化为十进制,ASCII码**

    bool ok;
    QStringList list;

//初始化list的内容为:list = ("30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "43", "44", "4D", "4E")
 //初始化list
    for(int i =0 ;i<10;i++)
    {
        QString temp = QString::number(30+i,10);
        list<;
    }
    list<<"43"<<"44"<<"4D"<<"4E";

    qDebug()<<"list ="<;                   //list的十六进制数初始值
    for(int i = 0 ;i
    {
        QString str_hex = list.at(i);           //获取十六进制数
        int dec = str_hex.toInt(&ok,16);        //十六进制转十进制
        char st = dec;                          //十进制数用char类型表示--->必须有此步直接转化不可行
        QString str_ascii = QString(st);        //转化为ASCII值
        qDebug()<<"  str_hex ="<"  dec ="<<dec
                <<"  st ="<<st
                <<"  ascii ="<;
    }

    //清空以便于之后的重新赋值
    list.clear();

ASCII码值转化十六进制,十进制数;十六进制字符值转十进制,ASCII码值;_第1张图片

ASCII码值转十六进制,十进制数


    //初始化list
    for(int i =0 ;i<10;i++)
    {
        QString temp = QString::number(i,10);
        list<list<<"C"<<"D"<<"M"<<"N";
     qDebug()<<"list ="<<list;                   //list的ASCII码初始值
    for(int i = 0 ;i<list.size() ;i++)
    {
        QString str_ascii = list.at(i);              //获取ASCII值
        QByteArray ascii = str_ascii.toLatin1();     //转化为QByteArray类型便于转化为十六进制
        QByteArray ascii_H = ascii.toHex();          //将ASCII值转化为十六进制数值
        QString str_hex = QString(ascii_H).toUpper();//十六进制数的大写表示
        int dec  = str_hex.toInt(&ok,16);            //十六进制数转化为十进制数
        qDebug()<<"  str_ascii ="<"  ascii ="<"  ascii_H ="<"  str_hex ="<"  dec ="<

ASCII码值转化十六进制,十进制数;十六进制字符值转十进制,ASCII码值;_第2张图片

若有错误请谅解!

你可能感兴趣的:(QString,ascii-16进制转换)