maniac84
Full Member level 6
Hi there. Is there a way in C coding to convert like the way like this? For example I got '1' equals to 0x31, and '2' equals to 0x32. I want to convert 0x31, 0x32 to 0x12.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
unsigned char c1,c2;
unsigned char R;
c1='1' -'0';
c2='2'-'0';
R=c1<<4 + c2; // 0x12
char Texte[16];// table of char
char *txt; // pointer
.......
txt=&Texte[0]; // initialise pointer
*txt=c1;
*txt+1=c2;
*txt+2=0; // end of string
// now txt point on the result '12'
hello,
Code:unsigned char c1,c2; unsigned char R; c1='1' -'0'; c2='2'-'0'; R=c1<<4 + c2; // 0x12
or Maybe you want to get "12" ?
Code:char Texte[16];// table of char char *txt; // pointer ....... txt=&Texte[0]; // initialise pointer *txt=c1; *txt+1=c2; *txt+2=0; // end of string // now txt point on the result '12'