Logout

4.1.6 Outline three situations, with each one providing an example of when and where on e of the errors in 4.1.5 can occur. Each situation should show a different error, that is all three errors should be described.

(No teaching notes for this one.)

Sample Question:

Numeric data is stored in a computer in binary format.

(a) Using a 7-bit two’s complement binary format show how the following integer
values would be represented.

.
.
.
(c) Explain what would occur if an attempt was made to store an integer that
exceeded the largest value allowed. [3 marks]


JSR Notes:

Beyond a good dictionary definition with a basic example, as seen in the JSR notes to 4.1.5, you should take your time with the actual examples on pages 228 and 229, which go into details of what actually happens when these errors occur – it takes you to the actual 0s and 1s level, and shows you the results of each of these errors.  Another place to see an example at this level is back in 4.1.1 where the binary addition rules are gone over.

And you really should have an appreciation of what goes on at the binary level with each of these errors.  Because the assessment statement asks you to outline situations in which each could happen.  So that means that you need to have one example each at hand to explain each, not just at a basic level, but in an outline manner.

Here’s an example for each:

Truncation:
double x = 2.4;
double y = 3.3;
int z = int(x + y);
System.out.println(z);

The output is:
5

Underflow:
Assuming a 10 bit floating-point format, with mantissa of 6 bits, and exponent of 4 bits, with MSB:
double x = 2.4;
double y = 0.00000000001;
double z = x / y;

Error of attempted division by 0 will be reported (hopefully), since y is too precise a value to be represented, and will actually be 0.

Overflow: (Assumes the type byte is an 8-bit signed integer.)
byte x = 127;
byte y = 1;
byte z = x + y;
System.out.println(z);

The output is:
-128