ASCII码值转化十六进制,十进制数;十六进制字符值转十进制,ASCII码值;
生活随笔
收集整理的這篇文章主要介紹了
ASCII码值转化十六进制,十进制数;十六进制字符值转十进制,ASCII码值;
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
**用字符表示的十六進(jìn)制值轉(zhuǎn)化為十進(jìn)制,ASCII碼**
bool ok;QStringList list;//初始化list的內(nèi)容為:list = ("30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "43", "44", "4D", "4E")//初始化listfor(int i =0 ;i<10;i++){QString temp = QString::number(30+i,10);list<<temp;}list<<"43"<<"44"<<"4D"<<"4E";qDebug()<<"list ="<<list; //list的十六進(jìn)制數(shù)初始值for(int i = 0 ;i<list.size() ;i++){QString str_hex = list.at(i); //獲取十六進(jìn)制數(shù)int dec = str_hex.toInt(&ok,16); //十六進(jìn)制轉(zhuǎn)十進(jìn)制char st = dec; //十進(jìn)制數(shù)用char類型表示--->必須有此步直接轉(zhuǎn)化不可行QString str_ascii = QString(st); //轉(zhuǎn)化為ASCII值qDebug()<<" str_hex ="<<str_hex<<" dec ="<<dec<<" st ="<<st<<" ascii ="<<str_ascii;}//清空以便于之后的重新賦值list.clear();
ASCII碼值轉(zhuǎn)十六進(jìn)制,十進(jìn)制數(shù)
//初始化listfor(int i =0 ;i<10;i++){QString temp = QString::number(i,10);list<<temp;}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(); //轉(zhuǎn)化為QByteArray類型便于轉(zhuǎn)化為十六進(jìn)制QByteArray ascii_H = ascii.toHex(); //將ASCII值轉(zhuǎn)化為十六進(jìn)制數(shù)值QString str_hex = QString(ascii_H).toUpper();//十六進(jìn)制數(shù)的大寫表示int dec = str_hex.toInt(&ok,16); //十六進(jìn)制數(shù)轉(zhuǎn)化為十進(jìn)制數(shù)qDebug()<<" str_ascii ="<<str_ascii<<" ascii ="<<ascii<<" ascii_H ="<<ascii_H<<" str_hex ="<<str_hex<<" dec ="<<dec;}若有錯誤請諒解!
總結(jié)
以上是生活随笔為你收集整理的ASCII码值转化十六进制,十进制数;十六进制字符值转十进制,ASCII码值;的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java大小写转置,javascript
- 下一篇: nedc和epa续航里程什么意思_NED