943,547 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 466
  • C++ RSS
Nov 6th, 2008
0

char to hexidecimal

Expand Post »
I have a buffer of chars. I want to display them in a text box as hex. is there a simple way to do this? Thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
Nemoticchigga is offline Offline
98 posts
since Feb 2008
Nov 6th, 2008
0

Re: char to hexidecimal

You could always use something like this....ofcourse you need to adapt it

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. int main(void){
  8.  
  9. ostringstream hello;
  10.  
  11. hello << hex << (int)'A';
  12. cout << hello.str();
  13.  
  14. cin.get();
  15. return 0;
  16. }

Chris
Last edited by Freaky_Chris; Nov 6th, 2008 at 1:16 pm.
Reputation Points: 325
Solved Threads: 118
Master Poster
Freaky_Chris is offline Offline
702 posts
since Apr 2008
Nov 6th, 2008
0

Re: char to hexidecimal

what I want is something like this

C++ Syntax (Toggle Plain Text)
  1. char buffer[10];
  2. buffer[0] = 0x5F;
  3. TextBox->Text = buffer[0];

i need to cast or a function to convert or something that I dont know about to get the text box to display 0x5F or 5F. Thanks.
Last edited by Nemoticchigga; Nov 6th, 2008 at 1:34 pm.
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
Nemoticchigga is offline Offline
98 posts
since Feb 2008
Nov 6th, 2008
0

Re: char to hexidecimal

Can you not adpot what i gave you....or am i gonna have to spoon feed you?

C++ Syntax (Toggle Plain Text)
  1. ostringstream hello;
  2. char buffer[10];
  3. buffer[0] = 0x05;
  4. string blah;
  5.  
  6. hello << hex << (int)buffer[0];
  7.  
  8. blah = hello.str();
  9. TextBox->Text = blah;
Reputation Points: 325
Solved Threads: 118
Master Poster
Freaky_Chris is offline Offline
702 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Deleting an index of array using pointers
Next Thread in C++ Forum Timeline: Classic C++ VS Visual C++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC