Input a Hex number and output hex number to a text field

This is a discussion on Input a Hex number and output hex number to a text field within the C++ Programming forums, part of the General Programming Boards category; Ok, I am total newb at programming but learning as I go. This is not homework. I am building a ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Location
    Boulder, Co
    Posts
    6

    Input a Hex number and output hex number to a text field

    Ok, I am total newb at programming but learning as I go. This is not homework. I am building a simple gui to show hex and bin values of certain buffers.

    I have a function that returns a hex value, say 81, as a unsigned char. I want to take this value and write it out to a text box. The text box requires it to be a string array. What I am doing:

    InputPacketBuffer[1] = 0x81;

    String^ TestTagText = Convert::ToString(InputPacketBuffer[1]);
    TagData->Text = TestTagText;

    In the text box I get 129, which is the decimal representation of 81h. Any ideas on how to keep the displayed value as 81 and not 129?

    Any tips or direction is much appreciated. Ultimately I need this to display HEX and BIN representation of the buffers, just need a nudge in the right direction to get me moving.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That looks like C# (or perhaps "Managed C++"?).

    If you want a C++ solution, I'd suggest using stringstream and the stream modifier hex.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,246
    Quote Originally Posted by matsp View Post
    That looks like C# (or perhaps "Managed C++"?).
    More like Mangled C++?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    You could use
    Code:
    InputPacketBuffer[1].ToString("x")
    or
    Code:
    String::Format("x", InputPacketBuffer[1]);
    http://msdn.microsoft.com/en-us/library/fht0f5be.aspx
    Woop?

  5. #5
    Registered User
    Join Date
    Mar 2009
    Location
    Boulder, Co
    Posts
    6
    Awesome guys/gals...Thank you. It is mangled C++. I am learning C and C++ as I go on this project. I feel like a monkey just mashing buttons, hoping something will come out right.

    I am just Electrical Engineer that has only done board designs previously. First time doing a project from front to back. HW, FW, and SW...good times.

    EDIT: Since I never see follow ups on what worked, I thought I would post it incase some searches and needs the same. Here is what I got to work:

    String^ TestTagText = String::Format( "{0:X}", InputPacketBuffer[1] );

    Thanks again for the help!
    Last edited by zoobaby; 05-13-2009 at 10:17 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  3. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  4. Outputting to a File Modified Text
    By alpha in forum C++ Programming
    Replies: 8
    Last Post: 11-24-2003, 07:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21