Converting a "negative" binary string to a Hex
-
wrote on 20 Oct 2022, 15:10 last edited by
Hi. I have the following 32 character binary string, as an example.
QString binResult="11000001001101100001010001111011"
Since it's 32 chars long and starts with a "1", my understanding is that if I use the toInt() function, it will be interpreted as a negative value and cannot be converted. Something like this:
unsigned int reee = binResult.toInt(nullptr, 2);
returns a 0.
I would like to convert this from a binary to a Hex, so I need the value of the QString properly stored. Is there a function that would allow me to circumvent the issue of toInt interpreting this as a -ve value?A workaround would be to cut the QString to 2 16 char parts, but I am wondering whether there exists a function that would solve my issues.
-
If you want an unsigned int then use
QString::toUInt()
instead ofQString::toInt()
.
1/2