user10115048
user10115048

Reputation:

Converting a QString with a binary into a QString with a hex

I am wondering what the most efficient way would be to convert a binary that is saved as a QString into the corresponding Hex and save it in the same QString

QString value = "10111100" 

into

value = "bc"

Upvotes: 0

Views: 3569

Answers (1)

PlinyTheElder
PlinyTheElder

Reputation: 1494

It's simple. First convert your binary string to an integer:

QString value = "10111100";
bool fOK;
int iValue = value.toInt(&fOk, 2);  //2 is the base

Then convert the integer to hex string:

value = QString::number(iValue, 16);  //The new base is 16

Upvotes: 1

Related Questions