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. How to display int as hex?
Forum Updated to NodeBB v4.3 + New Features

How to display int as hex?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 5.4k Views 1 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.
  • EngelardE Offline
    EngelardE Offline
    Engelard
    wrote on last edited by Engelard
    #1

    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_1980A 1 Reply Last reply
    0
    • EngelardE 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_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      EngelardE 1 Reply Last reply
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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
        0
        • aha_1980A aha_1980

          @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.

          EngelardE Offline
          EngelardE Offline
          Engelard
          wrote on last edited by
          #4

          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
          0
          • EngelardE Offline
            EngelardE Offline
            Engelard
            wrote on last edited by
            #5

            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
            0

            • Login

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