In this lesson we will explore a strange way to do decimal arithmetic, using decimal because you are already familiar with it. The purpose of doing this is to establish some new (strange) techniques that are relevant to binary arithmetic, using familiar decimal numbers. In a following lessons we will be looking at binary arithmetic, using the techniques introduced in this lesson. That way, you don’t have to learn the techniques presented here and binary arithmetic at the same time. (In the comments, please let me know if this splitting the topic helped with understanding)
Describe doing decimal arithmetic with only 3 digits. Only allow 0..9
Show addition overflow, introduce truncated results, not rounding
Give an example of calculating an average, where overflow does not occur, and we get the right answer. This is a reminder of how an average is calculated. (50 , 65, 47, 99) Highlight the correct answer, and notice no rounding of the fractional part, just truncation at the right end of the number.
Calculate an average where the intermediate results exceed 3 digits, (850, 875, 600, 437) leading to a final result that only needs 3 digits, but the result is wrong due to intermediate truncation. Hmmm, maybe also see that (850 – 875) + (600 + 437) is different, if the operands and braces are moved around.
Show that negatives are not supported, and although subtraction can be performed, not all results can be displayed
With decimal, we rarely think about limits to number of digits, but what if you had to do calculations on your calculator that used numbers with 50 digits? While this is getting into an extreme example for normal day to day calculations, it does point out that there are limits that we don’t normally think about. When we get to binary arithmetic on computers and embedded processors, the limits are real, and may surprise you about how restrictive they are.