Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved How to display int as hex?

    General and Desktop
    3
    5
    4050
    Loading More Posts
    • 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.
    • Engelard
      Engelard last edited by Engelard

      I remember some time ago i was doing such thing in VS, but now i want to convert my local variable from decimal, to hex. AND without using QStrings.

      int  val = 15;
      

      after some function should become:

      int val = F;
      

      It would be even nicer if somehow i would be capable convert not just to hex, but even convert that number in to memory address, like that:

      int val = 0x0000000F;
      

      But for the beginning simple inHex conversion will be suffice.

      aha_1980 1 Reply Last reply Reply Quote 0
      • aha_1980
        aha_1980 Lifetime Qt Champion @Engelard last edited by

        @Engelard

        Sorry, I don't understand what you want to do.

        Note that: int val = 15; and int val = 0x000000F; are binary identical in memory, but int val = F; is syntactical wrong.

        Qt has to stay free or it will die.

        Engelard 1 Reply Last reply Reply Quote 3
        • mrjj
          mrjj Lifetime Qt Champion last edited by

          Hi
          Hex is a notion/presentation concept so im not sure what your goal is.
          Anyway, if you dont want to use QString, there is also
          std::hex

          1 Reply Last reply Reply Quote 0
          • Engelard
            Engelard @aha_1980 last edited by

            Sorry, I don't understand what you want to do.

            I can assign manually my int variables like "int val = 0x01;" but i want to do the same but with program functionality , so program can accept such value as a memory adress, which must be in hex.

            Note that: int val = 15; and int val = 0x000000F; are binary identical in memory, but int val = F; is syntactical wrong.

            Well, QString::number(val, 16); returns int in hex and displays it for me in TextBrowser as just "f".

            1 Reply Last reply Reply Quote 0
            • Engelard
              Engelard last edited by

              I just find out that c++ also can accept memory addresses in decimal. Why did'nt thought about that before :D

              1 Reply Last reply Reply Quote 0
              • First post
                Last post