6 Representing numbers in binary
Now looking at the encoding for numerals in Table 2, we can see how the characters 0–9 are represented in UTF-8.
Table 2 ASCII table for numerals
Note, this is the character representation of the number to display that number on a screen or to print in a document. It is not the actual representation that a processor will use when preforming numerical calculations!
Consider the number ‘11’. To print this number we use two characters, a ‘1’ followed by another ‘1’. However, this is a very inefficient way for a processor to handle numbers in a calculation. Instead, the number eleven can be simply encoded in a byte as 00001011. That is one byte, not two, and in a form that instructions such as add and subtract can be directly applied to the bits for efficient calculations. There are other special ways to encode numbers for processing. They are beyond the scope of this course.
Modern computer programming languages such as Python handle the conversion between the two representations of a number automatically. However, in many languages it is for the programmer to declare in the program whether a number is to be used say for printing on a report, or for calculating the values to be printed.
The logic of the program informs the processor how to handle each byte, whether it represents a character or a number, or even another data format altogether as you shall see in the next section.