Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert decimal to hexadecimal with Qt programming? [closed]

Tags:

c++

qt

How to convert decimal to hexadecimal with Qt programming? Such as 69 switch to 45, 56 switch to 38 and so on... I try like this

QString str = QString::number(s.at(i).unicode());
bool ok;
qDebug() << str.toUtf8();

but failed. I need to convert this string "E8A5" ASCII switch to hexadecimal number or string.

like image 629
Kevin Avatar asked May 05 '16 08:05

Kevin


1 Answers

Source string:

QString str = QString::number(s.at(i).unicode());

Then:

Step 1. Convert string to integer

int nValue = str.toInt();

Step 2. Convert integer back to Hex string, using Qt

QString result = QString::number( nValue, 16 );

Step 3. Convert to uppercase (optional)

qDebug() << result.toUpper();

or all together in shorter form:

qDebug() << QString::number( str.toInt(), 16 ).toUpper();
like image 171
evilruff Avatar answered Oct 22 '22 16:10

evilruff