Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Converting a "negative" binary string to a Hex
Forum Updated to NodeBB v4.3 + New Features

Converting a "negative" binary string to a Hex

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 322 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dummie1138
    wrote on 20 Oct 2022, 15:10 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 20 Oct 2022, 15:30 last edited by
      #2

      If you want an unsigned int then use QString::toUInt() instead of QString::toInt().

      1 Reply Last reply
      4

      1/2

      20 Oct 2022, 15:10

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved