0

I want to print out an integer value which is computed in the program on a uart screen. I am basically creating a data logging system. The user must be able to view the times when a character arrives.

I am not able to use printf or snprintf or sprint as i am creating a time triggered system and printf takes some time to execute. I have searched stackoverflow and found a few idea, however they do not seem to work. eg itoa, char c int i = 26; c = (char) i ( does not work but gives weird characters)

Thank you

2
  • Just do a digit to ascii char mapping. Commented Nov 13, 2012 at 23:19
  • How would you do digit to char mapping, i never came across that process before Commented Nov 14, 2012 at 0:08

1 Answer 1

1

In your example you try to print 26 decimal. This is not a printable character in the ASCII character set. You would have to convert the 2 to ASCII (50 decimal) and then the 6 to ASCII (Decimal 54) to print 26. In other words it would have to be one digit at a time.

You could do this by iteratively adding decimal 48 to each digit in your variable (the offset for ASCII zero) and load the ASCII digit from most significant digit to least in a buffer and transmit that.

Sign up to request clarification or add additional context in comments.

1 Comment

Okay would something like this work int new_value[4]; char buf_temp[4]; int temp,x; for (x = 0; x < 4; x++) { new_value[x] = temp % 10; temp = temp / 10; buf_temp[x] = new_value[x] +48; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.