Thread: Conversion from ascii to decimal

1. Conversion from ascii to decimal

Hi there, need some help in my code here. My program suppose to display a number(decimal) on the screen via uart when I send a number but it is displaying in ascii form. I tried debugging it but there is no solution for it. When I send 88 it can only display X. I have attached the code. Please help me. I`m using MikroC compiler and i`m using a PIC.

pulserate = 88;
Temp = (pulserate - '0');
newline();
UART1_Write_Text("Your Heartbeat rate is : ");
newline();
UART1_Write(Temp);
newline();

2. Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion
Lookup 88 in this table.

To convert something like this, you need
char1 = (pulserate / 10) + '0';
char2 = (pulserate % 10) + '0';

3. The number 88 is only an example that I injected. How if the user key in some other random numbers like 100 or 58 ?? I need a constant code to automatically perform this calculations. Is it possible ?? Thank you.

4. Sure, just have /10 and %10 in a loop.

5. I did that but I get other symbols from the ascii table. Like for 100, I got the output :0. Is there anything that can be done ?? Thank you.

6. You keep saying "It can't be done", but you never post any code to show us just exactly in what way you're making a mess of it.

And no, I'm not just going to give you the code.
Yes, it is very easy to write.

7. I did the code. Please stop blaming that I did not write the code. I can show the you code. As a prove I did it. And this is the first time I`m using Mikro C and that is why I am asking for help. Thank you very much for your guidance all this while.

Temp = pulserate ;
char1 = (pulserate / 10) + '0';
char2 = (pulserate % 10) + '0';
char3 = (pulserate %100) + '0';
newline();
UART1_Write_Text("Your Heartbeat rate is : ");
newline();
UART1_Write(char1);
UART1_Write(char2);
UART1_Write(char3);
newline();

8. > char3 = (pulserate %100) + '0';