Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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!

share|improve this question
1  
What other way to get printable characters on the screen can there be except to create printable characters? –  S.Lott Jul 22 '11 at 20:36
    
@S: I dont know. Are there any? –  Tim Jul 22 '11 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 Jul 22 '11 at 20:44
add comment

3 Answers

up vote 7 down vote accepted

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.

share|improve this answer
3  
Right, but twos-complement :) BTW, one summer I did design work for the Model 30-series teletypes. –  Mike Dunlavey Jul 22 '11 at 21:22
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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