Changing an int to a hexadecimal format

Hello, I've been wondering how it's possible to change an integer to a hexadecimal format is VC++ 8 .net 2.
With Thanks,
                   Gal Beniamini.


Answer this question

Changing an int to a hexadecimal format

  • salmanpirzada

    No: internally when your application is running an integer is stored in hexadecimal format (well actually if you go low enough it is stored in binary format).

    To do this as part of a Windows Form Application I would have a textbox in which the user inputs the string: then I would do something like:

    String^ inputString = inputTextBox->Text;

    if (inputString != nullptr)
    {
       // Allow for really large values
       Int64 value;

       try
       {
          value = Int64::Parse(inputString);
       }
       catch (OverflowException^ e)
       {
          // ...
       }
       catch (FormatException^ e)
       {
          // ...
       }

       String^ outputValue = value.ToString("x");

       outputTextBox->Text = outputValue;  
    }


  • schmaltzkj

    Hello, Jonathan, isn't an integer in decimal format Secondly, I am not writing a console application, I am writing a Windows Forms one, and what I really meant was that I created an app in which the user types a string and gets the ASCII value of his string and then I will be converted to it's Hexa equivilant.

  • Rod Fraga

    Hi: Gal an int already is in hexadecimal format: think about it Smile. But I presume that what you want to do is print it out in hexadecimal format. There are several ways to do this: in regular C and C++ I tend to use:

    int i = 42;

    printf("i = 0x%08x\n", i);

    In C++/CLI I would use:

    Console::WriteLine("i = 0x{0}", i.ToString("x8"));

    I never did take the time to work out how to do this with IO streams other than the "hacky":

    std::cout << "i = 0x" << reinterpret_cast<void*>(i) << std::endl;


  • Paulvo

    Hello again, I did not mean the way an integer is stored, I meant the way it's desplayed... But nevermind that. Thanks for your answer.

  • Changing an int to a hexadecimal format