Convert hexadecimal to decimal and vice-versa in Qt

From Qt Wiki
Jump to navigation Jump to search

Template:Abstract

Conversion from Hexadecimal to Integer and vice-versa is frequently required in Qt, for example if you want to show UID of application to user then you will get it in 76ytuiytuityutyutututyutyutyu form, so need to convert in hexadecimal. Similarly when you want to uninstall application silently, then you need to convert hexadecimal to integer, because 76ytuiytuityutyutututyutyutyu method take UID in integer form, not in hexadecimal. Template:ArticleMetaData

Hexadecimal to decimal conversion[edit | edit source]

/* hexadecimal 0xED8788DC is equivalent to decimal 3985082588 */ QString str = "0xED8788DC"; bool ok; uint appId = str.toUInt(&ok,16); //appId contains 3985082588

Decimal to hexadecimal conversion[edit | edit source]

/* decimal 3985082588 is equivalent to hex ED8788DC */ uint decimal = 3985082588; QString hexadecimal; hexadecimal.setNum(decimal,16); //now hexadecimal contains ED8788DC // This is probably wrong, on3/20/19 i corrected the hex to dec

Template:Note