convert int to char dspic30f

Status
Not open for further replies.

kenobe

New Member
Hi
The mplab c30 compiler does not support itoa() function.
how do I change a hex number ie 0x55 to become a char '55' without using the printf().
Thanks
 
There is probably some easier way but this gets the job done,

Code:
	intVal=0x34;
	charout[0]=(intVal>>4)+0x30;
	charout[1]=intVal&0x0f+0x30;

Mike.
 

Hi Pommie
Thanks for your help.
but what I need is charout[0] = 55 , not charout[0]=5, charout[1]=5
 
Isnt't that just

charout=(char)intVal;

or even,

charout=intVal&0xff;

Mike.
 
I tried that too, but mplab c30 compiler does not work with casting and masking ,so it still does not solve the problem.
 
kenobe said:
I tried that too, but mplab c30 compiler does not work with casting and masking ,so it still does not solve the problem.

I found this hard to believe and so, I just tried the following,
Code:
#include <p30f2010.h>

unsigned int x;
unsigned char outchar;

int main(void){
	x = 0x45;
	outchar=(char)x;
	x = 0x45;
	outchar=x&0xff;
	x = 0x45;
	outchar=x;
	while(1);
}

It did exactly what I expected it to do.

Maybe you should post an example of what doesn't work.

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…