Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

convert int to char dspic30f

kenobe

New Member
:D 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.
 
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.
 

Latest threads

Back
Top