Program / Task Name:

   Checking the Sum

Level:

 

 Novice/Advanced

Point Value:

 

 5

 

Task Description

Before HP ships any computer, diagnostic software tests the components to ensure the machine works properly. One method for testing blocks of memory is called Checksum Verification. You will write a program to compute a checksum on a block of data.

  • The checksum for this program is an eight bit unsigned value which, when added to the unsigned sum of the data values, zeros the sum. This value is called the two’s compliment. For example, here is a four byte data block (all data values are in hexadecimal): 9E A6 58 80. The eight bit unsigned sum of the data values is 1C. The two’s compliment of 1C is E4 (notice that the eight bit unsigned sum of 1C and E4 is zero).

A diagnostic test would compare the expected checksum against the computed checksum. If the values did not match, then the test would fail.

Program Input

The input file (prob06.in) consists of 256 eight bit unsigned hexadecimal numbers. There are 16 lines, and 16 values on each line, separated by spaces. The program should handle upper case and lower case letters.

54 61 73 6b 20 44 65 73 63 72 69 70 74 69 6f 6e
0d 0a 42 65 66 6f 72 65 20 68 70 20 73 68 69 70
73 20 61 6e 79 20 63 6f 6d 70 75 74 65 72 2c 20
64 69 61 67 6e 6f 73 74 69 63 20 73 6f 66 74 77
61 72 65 20 74 65 73 74 73 20 74 68 65 20 63 6f
6d 70 6f 6e 65 6e 74 73 20 74 6f 20 65 6e 73 75
72 65 20 74 68 65 20 6d 61 63 68 69 6e 65 20 77
6f 72 6b 73 20 70 72 6f 70 65 72 6c 79 2e 20 4f
6e 65 20 6d 65 74 68 6f 64 20 66 6f 72 20 74 65
73 74 69 6e 67 20 62 6c 6f 63 6b 73 20 6f 66 20
6d 65 6d 6f 72 79 20 69 73 20 63 61 6c 6c 65 64
20 43 68 65 63 6b 73 75 6d 20 56 65 72 69 66 69
63 61 74 69 6f 6e 2e 20 59 6f 75 20 77 69 6c 6c
20 77 72 69 74 65 20 61 20 70 72 6f 67 72 61 6d
20 74 6f 20 63 6f 6d 70 75 74 65 20 61 20 63 68
65 63 6b 73 75 6d 20 6f 6e 20 61 20 62 6c 6f 63

Program Output

The program must compute the eight bit unsigned sum of the data values and the checksum. The program must write these two numbers in hexadecimal to the output file (prob06.out).  Please label the values as in the sample output given below:

unsigned sum: X5
checksum: XB

 

   
  (c) 2004 Hewlett-Packard Company