Chapter 16: Data Representation: Answers To Coursebook Questions and To Worksheet Questions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Chapter 16: Data representation:

Answers to coursebook questions


and to Worksheet questions
Syllabus sections covered: 13.1, 13.2 and 13.3

From the coursebook


Extension question 16.01
It would be desirable if each record contained a string variable for which the length of the string might be
different for different records. To read each record correctly, the record needs to include an integer value that
defines the length of the string. The software that handles the reading of the file needs to be able to read the
integer value then read that number of individual characters in the string before reading the remaining values in
the record.

Question 16.01
a The following table shows the addresses when 10 is used in the second row and the addresses when 11 is
used in the third row.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8

b The number of possible addresses in the file is equal to the number used for the division so there are more
when 11 is used.
c No
d Prime numbers can give an advantage if there are some key values used more often than others. If a non-
prime number is used, one or more of its factors may also be a factor for the key values most often used,
leading to the hash function being more likely to produce the same address many times.

Extension question 16.02


a Section 1.01 only considers unsigned integers so if strictly following the instructions in this question only
positive integer values can be considered.
For example, from Table 16.02 (a) the whole number part of 0111 is 011. The leading zero can be ignored so
we have the binary number 11, which is denary 3. Similarly, the first value for an exponent in Table 16.02 (c) is
0111, which converts to denary 7.

© Cambridge University Press 2019


If we extend the question to include signed integers then we can consider the binary value 1001 for an
exponent in Table 16.02 (c). This evaluates as -8 for the most significant bit then +1 for the least significant bit
to give the value -7 recorded in the table.
b Consider the positive value 0111. The two’s complement is 1001. If the two values are integers, 0111
represents denary 7 and 1001 represents denary -7.
If the 0111 represents 3.5 denary (2 + 1 + .5), 1001 represents -3.5 because you add -4 from the most
significant bit to the +.5). The rules apply irrespective of whether the binary pattern represents a signed
integer or a signed fixed-point real value.
Note: if you are converting a positive value to two’s complement you cannot start with a binary pattern that
begins with a 1. You have to place an 0 in front to convert from unsigned integer to a signed positive integer.

Extension question 16.03


The representations for the lowest magnitude values in table 16.03 are not normalised. A typical floating point
system is likely to allow this because otherwise the normalised alternative would be a poor approximation to the
correct value.

Task 16.01
The denary value has to be converted to a fixed-point real value first. This is done in two stages: the integer part is
converted first then the fractional part. If the approach taken is to convert the positive value first then take the
two’s complement later, we start by converting the 7. The binary equivalent of 7 is 111 but this is only used for
unsigned integers; here it must be represented as 0111. The fractional part .75 converts to .11 in binary.
Converting 0111.11 to the two’s complement produces 1000.01. There is a short-cut route to this value, which is
to recognise that -7.75 is equal to -8 + .25, which is 1000 + .01.
To convert the binary value 1000.01 to a normalised form with a defined exponent we have to move the binary
point to follow the most significant bit. A shift of three places is required to give 1.00001 × 23. The floating-point
representation is therefore:
100001000 0011
(The gap between mantissa and exponent is there for ease of reading.)

Exam-style Questions
1 a 1 mark each for any of the following up to a maximum of 3: The answer could name a type, such as
enumerated or pointer (1), or give an example (1). A built-in data type has a pre-defined range of possible
values (1), used by any program (1), whereas for user-defined the programmer defines a specific range
unique to that program (1).
b i 1 mark each for any of the following up to a maximum of 2: Collection of components (1), each with a
value (1), can be different types, both built-in and user defined (1).
ii 1 mark each for any of the following up to a maximum of 2: Related data can be referenced with one
construct (1), very flexible because different types allowed for the components (1), a value for a
component can be accessed individually (1).

© Cambridge University Press 2019


iii TYPE
DECLARE AnimalName : STRING
DECLARE AnimalAge : INTEGER
DECLARE NumberInZoo : INTEGER
DECLARE LocationInZoo : STRING
ENDTYPE
(1 for each line correct, up to a maximum of 5; repeated errors penalised once)
2 a i Record (1), field (1).
ii 1 mark each for any of the following up to a maximum of 3: A text file contains character data (1),
formatted into lines (1), there are end-of-line (1) and end-of-file (1) characters. A binary file has data
in internal representation (1), contains records (1) with a defined format (1).
b i 1 mark each for any of the following up to a maximum of 4: No defined order for serial (1), searching
a serial file requires reading complete records until the data is found (1), defined order for
sequential (1), direct-access file has a position for a record, which is computed using an algorithm (1),
a sequential or direct-access file has a key field (1) used when searching for data (1).
ii 1 mark each for any of the following up to a maximum of 3: A serial file is typically used to store data
temporarily as it becomes available (1) with the intention of processing every single record at some
future time (1). Examples are: any commercial or business transaction file (1), a file recording the
ongoing progress of a sporting contest to be used later to create statistics (1).
iii 1 mark each for any of the following up to a maximum of 3: Typical use is for long-term storage of
data (1) when the contents will be continuously changing (1) and individual data items will needed to
be looked up (1); any sensible example (1).
3 a i Exponent (1)
ii Two negative (1) because the most significant bit in the mantissa is 1 (1).
iii The first number (1), because the two most significant bits in the mantissa are different (1). An
answer of ‘number starts 10’ would be accepted.
iv After the first bit in the mantissa (1). All bits in the mantissa are significant (1), there are no wasted
leading zero bits (1).
v More bits for the mantissa gives increased precision (1). There must now be fewer bits for the exponent
(because total number of bits is limited to 16), so the range of possible values is reduced (1).
b 12 converts to 1100 (1), adding the sign bit gives 01100 (1). There are only three bits left for the fractional
part (1), .43 converts to .011 (1) so the binary value is 01100.011 (1), which must be converted to
0.1100011 × 24. The floating-point representation is:
01100011 00000100
This final answer would get the full 5 marks, otherwise partial marks are available as indicated.
4 This is Question 3 in 9608 Paper 31 June 2015. At the time of writing the published mark scheme is available
on the Cambridge International School Support Hub (requires registration). The Examiners Report for the June
2015 series is also available there and this may contain comments specific to this question.
The following are what the author of this chapter in the Teacher Resource would suggest as reasonable
answers with alternatives suggested where appropriate. Where a suggested answer includes bullet points,
each bullet point would be worth one mark up to the maximum mark allocation for the question.

© Cambridge University Press 2019


It is important to note that although the question mentions a programming language, the answers are
expected to be coded using pseudocode.
a i Enumerated
ii Record
iii MyMonthOfBirth ← DateOfBirth.ThisMonth
b i TYPE LocationRainfall
DECLARE LocationName : STRING
DECLARE LocationHeight : INTEGER
DECLARE TotalMonthlyRainfall : ARRAY[1..12] OF REAL
ENDTYPE
ii Possible statements could be:
 A sequential file is only used when there is an intention to sort the records
 A serial file can have new records appended to the end of the file
 Searching a sequential file is quicker than searching a serial file but this advantage is minimal for
such a small file.
Cambridge International AS & A Level Computer Science 9608 paper 31 Q3 June 2015
5 This is Question 1 in 9608 Paper 32 November 2016. At the time of writing the published mark scheme is
available on the Cambridge International School Support Hub (requires registration). The Examiners Report
for the November 2016 series is also available there and this may contain comments specific to this question.
The following are what the author of this chapter in the Teacher Resource would suggest as reasonable
answers with alternatives suggested where appropriate.
a
0 1 1 1 0 0 0 0 0 0 0 0 0 0 1 0

3.5 converts to 11.1 in binary, but 0 must be put at the start to ensure it is a positive value in two’s
complement form.
Then 011.1 has to be changed to 0.1110000 to produce a normalised representation that fits the 8-bit
mantissa with the binary point in the correct position. This has involved a shift of the binary point by two
places to the left so the exponent has to be the binary for 2.
b
1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0

Again, this can begin by converting 3.5 to 011.1 in binary (the 0 must be placed at the start). To convert
this to a negative value the two’s complement has to be taken, which produces 100.1. This is expanded to
1.0010000, which has involved a shift left of two places so the exponent is the binary for 2.
c 14
The exponent is 4 so the mantissa has to have the binary point shifted right by four places :
0.1110000 becomes 01110.000. The denary is 8 + 4 + 2 = 14
d i It is normalised
ii Because the two leftmost bits in the mantissa are different.

© Cambridge University Press 2019


e
1 0 0 1 0 0 0 0 0 1 1 1 1 1 1 1

Cambridge International AS & A Level Computer Science 9608 paper 32 Q1 November 2016

Worksheet 16.1: for testing


basic understanding
1 a Enumerated
User-defined
b There is an implied order of values.
c Only the first one could, because the order of the listing of the values matches the clockwise order of the
compass points around the globe. The second definition has the items in alphabetical order, but this is
unlikely to be of any use.
2 TYPE TBook
DECLARE BookTitle : STRING
DECLARE BookPublisher : STRING
DECLARE BookAuthors : STRING
DECLARE DatePublished : DATE
DECLARE Classification : STRING
DECLARE FloorStored : INTEGER
DECLARE ShelfStored : INTEGER
DECLARE TotalCopies : INTEGER
DECLARE NumberAvailable : INTEGER
ENDTYPE
3

© Cambridge University Press 2019


4 a  Open the file for read access.
 Use the agreed hash function in conjunction with some data from the record to be stored to calculate
a hash key value that determines a position (an address) in the file.
 Jump to this position in the file.
 Check whether this position is empty or if it contains data.
 If the position is empty, create a record containing the data.
 If the position is not empty, carry out a sequential search starting at the next position (address) until
an empty one is found.
 Create a record containing the data at this position.
b  As with any storage system, a direct-access file can become full.
 Also, even if not full, the storage system can be badly organised so that writing to or reading from it
becomes inefficient (too slow).
 To minimise the chance of problems, the algorithm used for the hashing function must be carefully
chosen to allow a good spread of addresses available for use in the file.
 Even when care is taken as more data is added, there will soon be synonyms or collisions. This is
when a new data record is to be added but the hashing function calculates the same file position
(address) as that for a previously added record.
 A simple method to deal with this is to store the new record at the first available empty position after
the one indicated by the hash function.
 However, this method is limited by the space available before the next position identified by a
different result from the hashing function is reached.
 Alternatives are to jump to a free space made available at the end of the file or to leave a message at
the file position that identifies where all records directed there have been moved to.
5 A True, B False, C True, D True, E False, F True
The context here is that if a program is reading from or writing to a file the most efficient method is to use a
binary file. This stores the data in the coding used internally by the computer. If a program has computed an
arithmetic value and this has to be output to a printer or to a monitor the value has to be converted to
character form. This time-consuming activity is not necessary if the value is just to be stored in a file for future
use by a program.
6 a This is intended as a paper exercise so the question of whether the value should be stored in a computer
as sign and magnitude or two’s complement need not be considered.
The value in binary is simply –100011.001
b Because the fractional part cannot be expressed exactly.
c The method described in worked example 16.01 in the coursebook must be used.
A sensible value is 11001.0101.
The fraction .33 is approximated as .3125 (1/4 + 1/16).
A more accurate binary value could be obtained by including more digits after the binary point but the
progress towards a closer value would be slow.
d The value 11001.0101 is only suitable as an unsigned value. However, a more detailed answer could be
provided which considers storage in a computer. The denary value is positive so the binary representation
for a signed value must start with a zero. Provided that the storage space is large enough, a zero can be
added at the start. This then automatically becomes a two’s complement value for a positive number.

© Cambridge University Press 2019


7 A, B, D, E, F
It is necessary to remember which part is called the mantissa or significand. The most important aspect is that
the designer of the floating point representation has an option as to how to divide the binary code, which
affects the range of the values and their precision. The radix has an implied value of 2 so it does not need to
have a code included.
8

Learners often find this type of question problematic. A systematic approach is needed, looking at the
mantissa and exponent separately. For each, the first bit sets the sign, 0 for positive and 1 for negative. Then
it is necessary to remember that for a negative number in two’s complement the first bit represents a
negative value but all of the others represent positive values.
9

There are some straightforward rules here. The first bit defines the sign. If the next bit is different the
representation is normalised. The binary point is initially after the first bit. To evaluate the number, the binary
point has to be moved according to the value for the exponent. Three of these have exponent value 3 (0011)
so the binary point moves three places right. Then the normal conversion of the binary can follow. Each one
should be checked!

© Cambridge University Press 2019


Worksheet 16.2: more challenging questions
1 The mantissa for the first example is 1.0101000 and the exponent is denary 7, so the mantissa becomes
10101000.
This evaluates as -128 + 32 + 8 = -88
For the second example the exponent is denary -8, so the mantissa becomes .000000001101000
This evaluates as 1/512 + 1/1024 + 1/4096 = 0.003173828
2 a 01111111 0111
This is straightforward, with the biggest positive values for the mantissa and exponent, so both are filled
with 1 bits following the 0 sign bit.
b 00000001 1000
This answer ignores the value for zero. The smallest positive value must have all zeros in the mantissa
except for the least significant bit. For the exponent, the initial 1 bit represents -8; if any other bit is 1, the
exponent would be a positive value that lessens the magnitude. Note that the representation is NOT a
normalised one. Floating-point processors have to decide whether or not to use unnormalised
representations for numbers close to zero.
c 10000000 0111
d 11111111 1000
Again, this is unnormalised.
3 a For the positive value the conversion is straightforward. The mantissa needs the bits moving one place to
the left so the exponent must be reduced by one: 01010000 0101
It might appear strange that for the negative value, bits set to 1 can be moved off the left-hand end of the
mantissa but that is what happens. The mantissa needs the bits moving two places to the left so the
exponent must be reduced by two: 10100000 0001
b For the first value, the initial denary equivalent is 32 + 8 = 40 multiplied by 26, which is:
40 × 64 = 2560.
The normalised version is 64 + 16 = 80 multiplied by 25, = 80 × 32 = 2560, which gives the same value.
For the second value, the initial denary equivalent is
-128 + 64 + 32 + 8 = -24 multiplied by 23, which is -24 × 8 = -192.
The normalised version is -128 + 32 = -96 multiplied by 21, which gives the same value.

© Cambridge University Press 2019

You might also like