r/computerscience • u/UsualSpace_ • 14d ago
Discussion How are arbitrary precision integers converted into ASCII when printing?
I'm just wondering how this is done algorithmically speaking. It makes sense to just map each value to an ASCII digit, until you get to the value of 10 and above, which is something I haven't thought about until now.
I am thinking about an arbitrary precision unsigned integer in this question.
Edit: thank you all for your answers!
14
Upvotes
View all comments
7
u/pyrobola 14d ago
IIRC in one firmware blob I looked at,
printfsubtracted decreasing powers of ten in a loop, calculating and printing the digits in order. This was on an embedded ARM processor that had no integer divide.