Feb 26, 2002 #1 Stripey MIS Sep 19, 2005 3 ES How can I convert a buffer of binary data (unsigned char) to hex for displaying? Stripey
Feb 27, 2002 #2 Zyrenthian Programmer Mar 30, 2001 1,440 US well, first off, if the character buffer is NOT in base 10 you will need to use strtol to convert it. i.e. if your buffer looks like "10010010011110" you would do char* buffer[] = "10010010011110"; char* endPtr; int val = strtol(buffer,endPtr,2); // 2 is the base if you just want to print the output in hex format, sprintf or CString::Format with a %x will do that for you. Matt Upvote 0 Downvote
well, first off, if the character buffer is NOT in base 10 you will need to use strtol to convert it. i.e. if your buffer looks like "10010010011110" you would do char* buffer[] = "10010010011110"; char* endPtr; int val = strtol(buffer,endPtr,2); // 2 is the base if you just want to print the output in hex format, sprintf or CString::Format with a %x will do that for you. Matt
Feb 27, 2002 #3 mingis Programmer Jan 23, 2002 475 LT I doubt if the question was what Matt meant. May be simply for(ii=0; ii<buf_size; ii++) printf("%02x", buf[ii]); Upvote 0 Downvote
I doubt if the question was what Matt meant. May be simply for(ii=0; ii<buf_size; ii++) printf("%02x", buf[ii]);