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?

Thanks and regards!

  • 1
    What other way to get printable characters on the screen can there be except to create printable characters?
    – S.Lott
    Commented Jul 22, 2011 at 20:36
  • @S: I dont know. Are there any?
    – Tim
    Commented Jul 22, 2011 at 20:41
  • printable characters == printable characters. What else can possibly exist? Non-printable characters? You wouldn't see them, right? What are you really asking?
    – S.Lott
    Commented Jul 22, 2011 at 20:44

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.

  • 3
    Right, but twos-complement :) BTW, one summer I did design work for the Model 30-series teletypes. Commented Jul 22, 2011 at 21:22

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).

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.