thunderdan
()
Thu Jan 30 2003 05:22 PM
Converting; int to char

It's been a while since I've posted on this forum, but it's been a while since I've had to program a PIC chip! This Question relates to the humble old 16F84...

Is there an easy way to convert a type int to a type char? without using the printf() or 
sprintf() function? 

I've got a global int called RPM and I need to display that on an LCD; trouble is, my LCD rutine only accepts a string a chars! The fantastic tech staff at Hi-Tech gave me this e.g.

"You can use an int (16-Bit) as a char (8-Bit) by casting it. For example:
int var1 = 0x1234;
char var2;
var2 = (char) var1; // cast an int as a char"

But If I have 1520d stored in RPM I need to end up with 4 chars, '1' '5' '2' and '0' (all in decimal, I would realy need the ASCII e-q's but do you get the general drift??) Of course if the code that Hi-Tech supplied is correct, I don't really understand it so any help would be fantastic! Thanks Daniel!




Contact Us | Privacy statement HI-TECH Software

Powered by UBB.threads™ 6.5.5