In programming languages, when numbers (either integer, or real) are printed out, are they firstly converted to the codes of the readable characters that are meant to represent the numbers, and then the codes are then decoded into the readable characters?

For example, in C, functions such as printf can print out the value of an integer variable a to screen or files. Suppose the value of a is 1. Does printf first convert the number 1 to the number 0x31 which is the ASCII code of character 1 and then decode 0x31 to character 1 in its output?

3 Answers
3

printf() does the first half of what you say, with the "%d" print spec. A number in a variable is typically in Ones-complement binary (although other conventions exist, and have been used) and code in printf() does convert a number 1 into an ASCII code, and usually in 8-bits.

It's up to the output device, xterm, printer, dumb terminal, what-have-you, to take bytes and turn them into something optically readable by humans. An xterm converts the byte value 0x31 (if it's in ASCII or UTF-8 mode) into some bitmap, depending on the font and size of what it's printing. A traditional, ice age teletype would mechanically strike the paper with a '1' key.

Generally yes. Output to the console is usually done using ASCII Characters. The rendering engine in the BIOS/OS(depending which is doing the rendering) intrprets the ASCII Character and sets the proper pixels to display.

Technically the computer only knows 1's and 0's. The compilers writes the code to convert the ascii value 0x31 into bits. The rendering engine then takes that information and determines what commands to send to the display. The display takes that and uses that to determine what pixels to light up and how. There is an incredible amount of code that goes into actually displaying the character on the screen.

Yes. Up to 0x31. Is C involved into conversion of byte value 0x31 into ideographic symbol, shown as pixels on screen ? No. This part is implemented in hardware, or programmer can assume that it is hardware (when in most contemporary cases it is system software).

If you want to know where exactly the software ends, then it is area of system memory, containing character byte codes, which physically can be not a common RAM, but RAM or RAM-like addressable resource inside video hardware. (that is very old implementation, on contemporary machine with full OS it is about 5 indirections of memory mapping and software/firmware on top of this).