By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,873 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

How to convert a uint32_t to Ascii in C.

P: 3
I have a uint32_t variable. I want to prints it ASCII equivalent.
can anyone help me here.
May 13 '16 #1
Share this Question
Share on Google+
6 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Move the uint32_t to a char variable and print the char.

Originally, the char was to hold one character of the implementation code set used to implement C++. In this case the implementation character set is ASCII. So printing a char with 65 in it prints an A whereas printing a unint32_t will print 65.
May 14 '16 #2

Expert 100+
P: 2,398
Does your uint32_t variable have the value of an ASCII character (for example 65)?
If so, are you concerned with this print function working on a platform that does not use ASCII? That is, do you need to convert ASCII to the native character set?

Or does your uint32_t variable have an arbitrary value that you want to print in decimal or hexadecimal?
May 14 '16 #3

P: 3
that variable has an arbitrary value which is pretty large. for eg. "1295069243" in decimal.
Now i want to print its ASCII equivalent.
May 14 '16 #4

weaknessforcats
Expert Mod 5K+
P: 9,197
The ASCII equivalent of 65 is A. If you look at the ASCII table, all printable values are between 40 and 126.

There is no ASCII equivalent to 1295069243. What you have here is a decode of the bits in the uint32_t into a string of digits. In this case you can just display the unit32_t.
May 14 '16 #5

P: 3
Thanks for your response. do you have any example for that?
May 14 '16 #6

Expert 100+
P: 2,398
Take a look at printf.
May 15 '16 #7

Post your reply

Sign in to post your reply or Sign up for a free account.