How to display int as hex?



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


  • Qt Champions 2017

    @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 Champions 2017

    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



  • 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".



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.