A Level Computer Science Revision Notes
A Level Computer Science Revision Notes
Advanced
Data
Representatio
n © 2024 Exams Papers Practice. All Rights Reserved
Data Types
A data type is a classification that determines the type of data a variable can hold,
and specifying it is crucial as it defines the range of values and operations applicable to
that variable, ensuring accurate storage, manipulation, and interpretation of data
within a program.
“a” in ASCII
1100001
© 2024 Exams Papers Practice. All Rights Reserved
97 in denary
Built-in data types are predefined data User-defined data types are created by
types provided by a programming programmers to suit specific needs
language. within a program.
The programming language defines:
Eg. In Python, you can create user-
The range of possible values that can defined data types using classes.
be assigned to a variable when its type
has been chosen. Eg: Java Int Data
Type: -2,147,483,648 to © 2024 Exams Papers Practice. All Rights Reserved
2,147,483,647
The operations that are available for
manipulating values assigned to that
variable.
“a” + “b” = “ab”
3+5=8
For more help, please visit [Link]
16.1 Data Types
Class
Not a string
{4, 3, 5, 1,
{a, z,
2}s, f,
For more help, please visit [Link]
16.1 Data Types
{a, z,
2}s, f,
• Removing an existing data value
c}
For more help, please visit [Link]
James Gan
16.1 Data Types
Binary Code
All type of file is stored using a specific binary code that allows the file to be used as
intended.
A text file stores data in a human- A binary file stores data in a format
readable format according to a that the computer can interpret
character code (ASCII, Unicode). directly as sequences of bytes.
The organisation of a binary file is
based on the concept of a record.
File
Record
© 2024 Exams Papers Practice. All Rights Reserved Record
Binary files
• The number of fields per record must be known
• The size of each field (number of bytes) must be known as well
A file organization method where A file organization method where A file organization method allowing
records are arranged in a linear records are arranged sequentially data retrieval or storage at any
sequence, accessed sequentially and accessed in a predefined location within the file without
from start to end. order, typically from the beginning needing to sequentially traverse the
to the end, and modification often entire file.
Real-life Scenario: Daily requires re-writing the entire file.
transaction logs in a financial Record
institution. Each day, the institution Real-life Scenario: Order 1
records transactions sequentially in processing in an e-commerce Record
a log file, appending new platform.
© 2024Orders
Exams Papersplaced by Reserved
Practice. All Rights 2
transactions at the end. customers are stored sequentially in
a file, and the system processes Record
them one by one in the order they 3
were received.
Record
4
For more help, please visit [Link]
Subtopic
16.2 File organisation
1
KL FC 54545 Y
23455
© 2024 Exams Papers Practice. All Rights Reserved
Scanning through the index table is a lot faster
44343
than scanning through the entire table due to the
usage of efficient data structure (hash table / B-
54545 tree) - We will learn more in chapter 23.
Fil
1
Dat e
2
I a
Nam Ag
D e e 3
207 Jac 2
4
6 k 5
107 Muhamm 2 5
© 2024 Exams Papers Practice. All Rights Reserved
3 ad 4
507 Davi 2 6
7 d 9 7
8
For more help, please visit [Link]
Subtopic
16.2 File organisation
1
Dat Fil
I a
Nam Ag 1
D e e
e
207 Jac 2
6 k 5
2
107 Muhamm 2
3
507
ad
Davi
4 3
2
7 d 9
4
Hashing algorithm (example): 5
© 2024 Exams Papers Practice. All Rights Reserved
[Link] the ID number by 10.
6
[Link] the Remainder
7
8
For more help, please visit [Link]
Subtopic
16.2 File organisation
1
Dat Fil
I a
Nam Ag 1
D e e
e
207 Jac 2
6 k 5
2
107 Muhamm 2
3
507
ad
Davi
4 3 107 Muhamm 2
2 3
ad
4
7 d 9
4
Hashing algorithm (example): 5
© 2024 Exams Papers Practice. All Rights Reserved
[Link] the ID number by 10.
6 207 Jac 2
[Link] the Remainder 6 k 5
7 507 Davi 2
7 d 9
8
For more help, please visit [Link]
Subtopic
16.2 File organisation
1
Dat Fil
I a
Nam Ag 1
D e e
e
207 Jac 2
6 k 5
2
107 Muhamm 2
7
507
ad
Davi
4 3
2
7 d 9
A collision can occur in a hashing algorithm 4
when two different inputs produce the same 5
© 2024 Exams Papers Practice. All Rights Reserved
hash value.
6 207 Jac 2
6 k 5
107 Muhamm
ad
2 7 507 Davi 2
7 4 7 d 9
8
For more help, please visit [Link]
Subtopic
16.2 File organisation
1
One of the methods is to use a prime numebr of a similar size to the expected size of the file.
Dat
a
Nam
e
Jac
k
Muhamm
ad
Davi
d
File access
Access occurs sequentially from start Access also takes place sequentially, In direct access files using hashing,
to end, with data retrieved or but if the key value is known for the file access involves directly mapping
appended in a linear order. record containing the wanted data, the hashed key to a specific location
the process is faster because only in the file where the desired data is
key field values need to be read. stored.
3
4
5
6 207 Jac 2
6 k 5
7 507 Davi 2
7 d 9
For more help, please visit [Link] 8
Subtopic
16.2 File organisation
1
File deletion
Deleting in a serial file typically Data is transferred from the old file to Deleting in a direct access file
involves marking the record as a new one until the targeted record involves marking the specific location
"deleted" without physically for deletion or modification is as available, allowing it to be reused
removing it to maintain sequential encountered, after which any for new data.
order. changes are made, and the
remaining records are then copied to
the new file.
1
6.47 x 10
can be
written as
64.7
= 0.647 x 10
2
-1
647 x 10
© 2024 Exams Papers Practice. All Rights Reserved
1
6.47 x 10
can be
written as
64.7
= 0.647 x 10
2
-1
647 x 10
© 2024 Exams Papers Practice. All Rights Reserved
The only
sensible
choice
For more help, please visit [Link]
16.3 Real Numbers
Fixed-point representation
Fixed-point representation is a numerical format used in computing where a specific number of
bits are allocated for the fractional and integer parts of a fixed-length binary number,
enabling representation of fractional values with a fixed precision.
000 = 0.125
001 = 0.25
010 = 0.375
011 = 0.5
100 = 0.625
101 = 0.75
Eg (8 110 = 0.875
111 = 0.000
bits):
© 2024 Exams Papers Practice. All Rights Reserved
sign
bit 3 bits for fractional part
4 bits for whole numbers
For more help, please visit [Link]
16.3 Real Numbers 000 = 0.125
001 = 0.25
010 = 0.375
011 = 0.5
100 = 0.625
Fixed-point representation 101 = 0.75
110 = 0.875
111 = 0.000
1 1 0 1 1 1 0 1
sign
bit 3 bits for fractional part
4 bits for whole numbers
- 11.75
© 2024 Exams Papers Practice. All Rights Reserved
Eg (8
bits):
sign
bit 3 bits for fractional part
4 bits for whole numbers
Floating-point representation
A representation of real numbers that stores a value for the mantissa and a value for the
exponent.
E
+
- Mx
© 2024 Exams Papers Practice. All Rights Reserved
Floating-point representation
Assume that we are using 8 bits:
E 4 bits
+
-
4 bits
Mx
© 2024 Exams Papers Practice. All Rights Reserved
R
For more help, please visit [Link]
16.3 Real Numbers
Floating-point representation
There are multiple ways we can structure the 4 bits to change where is the binary
point.
Intege Point Fractional Value
r
011 1 3.5
M
011 0 3.0
+ 1 2.0
-
010
101 0 -3.0
4 bits © 2024 Exams Papers Practice. All Rights Reserved
100 1 -3.5
100 0 -4.0
Floating-point representation
There are multiple ways we can structure the 4 bits to change where is the binary
point.
Intege Point Fractional Value
r
0 111 0.875
M
0 110 0.75
+ 101 0.625
-
0
1 010 -0.75
4 bits © 2024 Exams Papers Practice. All Rights Reserved
1 001 -0.875
1 000 -1.0
Floating-point representation
There are multiple ways we can structure the 4 bits to change where is the binary
point.
Intege Value
r
0111 7
M
0110 6
+ 0101 5
- 1010 -6
4 bits © 2024 Exams Papers Practice. All Rights Reserved
-7
1001
1000 -8
Floating-point representation
Eg (8
bits):
sign
bit
+
- M E
Description Binary Denary
Code
© 2024 Exams Papers Practice. All Rights Reserved 7
Largest positive value 0 111 0.875 x 2 =
0111 112
-8
Smallest positive value 0 001 0.125 x 2 = 1 /
1000 2048
-8
Smallest magnitude negative 1 111 -0.125 x 2 = - 1 /
1000
value For more help, please visit [Link] 2048
7
Largest magnitude negative 1 000 -1 x 2 = - 128
16.3 Real Numbers
Comparison
Fixed point
representation
Descriptio Binary Denary
n Code
Largest positive value 0 1111 15.875
111
Smallest positive value 0 0000 0.125
001
Smallest magnitude negative 1 0000 - 0.125
value 001
Largest magnitude negative 1 1111 - 15.875
value 111 Floating point
representation
Descriptio Binary Denary
n
© 2024 Exams Papers Practice. All Rights Reserved Code 7
Largest positive value 0 111 0.875 x 2 =
0111 112
-8
Smallest positive value 0 001 0.125 x 2 = 1 /
1000 2048
-8
Smallest magnitude negative 1 111 -0.125 x 2 = - 1 /
value 1000 2048
7
Largest magnitude negative 1 000 -1 x 2 = - 128
For more help, please visit [Link]
value 0111
16.3 Real Numbers
In practice, using the largest possible magnitude for the value represented by the mantissa would achieve
optimum precision.
Denary 2 Denary - 4
Floating-point binary Floating-point binary
Denary Denary
representation representation
Representation Representation
4 4
0.125 x 2 0 001 0100 -0.25 x 2 1 110 0100
© 2024 Exams Papers Practice. All Rights Reserved
3 3
0.25 x 2 0 010 0011 - 0.5 x 2 1 100 0011
2 2
0.5 x 2 0 100 0010 -1.0 x2 1 000 0010
For more help, please visit [Link]
16.3 Real Numbers
Denary 2 Denary - 4
Floating-point binary Floating-point binary
Denary Denary
representation representation
Representation Representation
4 4
0.125 x 2 0 001 0100 -0.25 x 2 1 110 0100
3 3
0.25 x 2 0 010 0011 - 0.5 x 2 1 100 0011
© 2024 Exams Papers Practice. All Rights Reserved
2 2
0.5 x 2 0 100 0010 -1.0 x2 1 000 0010
Denary 2
Floating-point binary
Denary
representation
Representation
4
0.125 x 2 0 001 0100
2
0.5 x 2 0 100 0010
Denary - 4
Floating-point binary
Denary
representation
Representation
4
-0.25 x 2 1 110 0100
2
-1.0 x2 1 000 0010
Conversion of representations
Convert 9.75.
9.75 0100
1
Notes:
Convert the fractional part. .00 = 00
.25 = 01
9.75 11 .5 = 10
.75 = 11
Conversion of representations
Convert 9.75.
This gives an exponent value of 4 (we shift the point 4 times to the left).
Assume that 14 bits are allocated (10 bits for the mantissa and 4 bits for the
exponent),
Conversion of representations
Convert 9.73.
9.73 0100
1
Convert the fractional part.
Method = Multiply by 2 and © 2024 Exams Papers Practice. All Rights Reserved
record the whole number (4
bits)
Conversion of representations
Convert 9.73.
9.73 0100
1
Convert the fractional part.
Conversion of representations
Convert 9.73.
9.73 0100
1
Convert the fractional part.
01001.1011
For more help, please visit [Link]
16.3 Real Numbers
Conversion of representations
Convert 9.73.
Shift the binary point until beyond “10” (for positive number) to achieve
normalisation
01001.1011 0.1001101
1
This gives an exponent value of 4 (we shift the point 4 times to the left).
Assume that 14 bits are allocated (10 bits for the mantissa and 4 bits for the
exponent),
Conversion of representations
Convert -7.75.
7.75 011
1
Notes:
Convert the fractional part. .00 = 00
.25 = 01
7.75 11 .5 = 10
.75 = 11
Conversion of representations
Convert -7.75.
1000.01 100001
This gives an exponent value of 4 (we shift the point 4 times to the left).
Assume that 14 bits are allocated (10 bits for the mantissa and 4 bits for the
exponent),
Limited Range of Numbers: Floating-point representation has a finite range to store numbers,
resulting in limitations on both the minimum and maximum values that can be accurately represented.
This limitation can lead to underflow errors when representing extremely small numbers, causing loss
of precision or inaccuracies in calculations involving very small values.