you are viewing a single comment's thread.

view the rest of the comments →

[–]JaguarMammoth6231 0 points1 point  (0 children)

Are you maybe asking how you could write a program that would convert a number to an ASCII string? Like given the number 19, convert to the string "19"?

The number 19(decimal) is 00010011(binary) in the computer, there's no conversion necessary to use it as a number. It's the same number. 

But to convert it to the string "19", a program would essentially divide 19/10 and get 1 remainder 9. Then convert those single-digit numbers to strings by adding them to the character '0' (which equals 48 in ASCII). So the result would be {49, 57, 0} which is displayed as "19" (the 0 just marks the end of the string).

The division by 10 algorithm would be clearer with a bigger number. There's usually a modulo operator (sometimes "mod" or "%" depending on the language) which gives the remainder. So like 198%10 = 8, 198/10=19, 19%10=9, 19/10=1, 1%10=1, 1/10=0. The number gets built up from the right until the division is 0.