char to hexidecimal

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2008
Posts: 98
Reputation: Nemoticchigga is an unknown quantity at this point 
Solved Threads: 2
Nemoticchigga Nemoticchigga is offline Offline
Junior Poster in Training

char to hexidecimal

 
0
  #1
Nov 6th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: char to hexidecimal

 
0
  #2
Nov 6th, 2008
You could always use something like this....ofcourse you need to adapt it

  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.
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 98
Reputation: Nemoticchigga is an unknown quantity at this point 
Solved Threads: 2
Nemoticchigga Nemoticchigga is offline Offline
Junior Poster in Training

Re: char to hexidecimal

 
0
  #3
Nov 6th, 2008
what I want is something like this

  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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: char to hexidecimal

 
0
  #4
Nov 6th, 2008
Can you not adpot what i gave you....or am i gonna have to spoon feed you?

  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;
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 357 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC