Link to home
Start Free TrialLog in
Avatar of Confettis
Confettis

asked on

hex to char*...

Hello,
when I print the following,
      printf("\t%02x00\t",(const char *)test[0]);
      printf("\t%02x00\t",(const char *)test[1]);
      printf("\t%02x00\t",(const char *)test[2]);
...
I have this output:    7500            0c00            7800 ....
I want it in the following form: 750c78....
I found a method by setting the cmd-line position allways two placs back, but I think that there should be a more elegant method; does anyone knows a eleganter method??

Thanks a lot.
Avatar of Member_2_1001466
Member_2_1001466

printf ("%02x%02x%02x", (const char*) test[0], (const char*) test[0], (const char*) test[0])
Or if you need to put it in a loop use

 printf ("%02x", (const char*) test[i]);

x means hex display, 02 means 2 digits left filled with 0 to fit the width (of 2)

Your format was
\t: a tab
%02x: as above
00: "00" string constant with two zeroes.
\t: and a tab again.
Avatar of Confettis

ASKER

thanks a lot. It works fine with the second method.
(Do you also happen to know how I can convert a hex saved in a char* to a char* ?
Example:
char * hexa="616263...."
char texta[10];
texta// here "abc..." should be saved...)

I found that it is easily done with a CString, but I don't want to use MFC...
If you don't know it I'll open a new thread...

Thanks .
ASKER CERTIFIED SOLUTION
Avatar of Member_2_1001466
Member_2_1001466

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot.