You are on page 1of 262

O you who have believed, the idolaters are indeed

unclean, so let them not approach the Sacred


O Allah, dearest Islam and the
Mosque after this year of theirs. ۚ And if you fear
Muslims, humiliate polytheism and the
a family, then God will enrich you of His bounty, if
polytheists, destroy the enemies of the
He wills. ۚ Indeed, God is Knowing, Wise.
religion and protect the possession of
Islam. Lord of the worlds.

Fighting is ordained for you, and it is


hateful to you, and perhaps you hate a
thing which is better for you, and
perhaps you love it. ۚ A thing and it is
bad for you ۚ And God knows and you
do not know

I just need a fatwa for doing Jihad and kill Non-Muslims.

1
My name is Muhammad Affan Bukahri and I am from Pakistan.
People can call me Khalid as well. I don’t have any particular
degrees and I am just a student, of o-levels. While studying I started
making my notes for computer science, online on computer. I took
help from internet and from my class lectures to make these notes.
After making some notes, I thought to compile them neatly like a
book. Basically I just added some pictures in the notes so they
look like a book. That’s how this book came into being

(These all things were taught me by my respected teacher.)


(Most of my notes were made by the by the help of teacher’s notes, and these are all the important
words of my teacher)

2
Index
number Chapter name Page
number
1 Basics of computers & binary system (paper 1) 4 – 22
2 Hexadecimal (paper 1) 23 – 33
3 Data Storage (paper 1) 34 – 46
4 Data Transmission (Communication & Internet technologies) (paper 1) 45 – 55
5 Internet Principles of Operation (paper 1) 56 – 62
6 Computer Architecture & the fetch-execute cycle (paper 1) 63 – 68
7 Logic Gates (paper 2) 69 – 75
8 Input Devices (paper 1) 76 – 94
9 Output Devices (paper 1) 95 – 134
10 Network Hardware (paper 1) 115 – 120
11 Software (paper 1) 121 – 140
12 The Internet & it’s uses (paper 1) 141 – 164
13 Automated & Emerging Technologies (paper 1) 165 – 175
14 Cloud & encryption (paper 1) 176 – 181
15 Algorithm design & problem solving (paper 2) 182 – 206
16 Programming (paper 2) 207 – 236
17 Database (paper 2) 237 – 243
18 Memory storage devices (paper 1) 245 – 255
19 Operating Systems (paper 1) 256 – 259

3
Basics of computers & binary system chapter 1
What is computer?
• A computer is an electronic device, operating under the control of
instructions stored in its own memory that can:
1) Accept data (input),
2) Process the data according to specified rules,
3) Produce information (output),
4) Store the information for future use.

How computer works?


• Any digital computer carries out five functions in gross terms:
1) Takes data as input.
2) Stores the data/instructions in its memory and use them when
required.
3) Processes the data and converts it into useful information.
4) Generates the output.
5) Controls all the above four steps.

4
Computer Components
• There are two type of computer components:
 Hardware:
Computer hardware is the collection of physical
elements, “Tangible objects” that constitutes a computer system. The
actual machinery, wires, transistors and circuits … etc.
 Software:
Computer Programs: instructions and data.
Computer science
• Computer science is the discipline that seeks to build a scientific
foundation for such topics as computer design, computer
programming, information processing, algorithmic solutions of
problems, and the algorithmic process itself. It provides the
underpinnings for today’s computer applications as well as the
foundations for tomorrow’s application.
Binary system
• Computers use binary digits (0 and 1) to store data.
• A binary digit, or bit, is the smallest unit of data in computing. It is
represented by a 0 or a 1.
• Binary numbers are made up of binary digits (bits), e.g. the binary
number 1010110100101 and 1011100101111001.
• The circuits in a computer's processor are made up of billions of
transistors. A processor is an integrated electronic circuit that performs
the calculations that run a computer.
• A transistor is a tiny switch that is activated by the electronic signals it
receives.
• The digits 1 and 0 used in binary reflect the on and off states of a
transistor.

5
• Computer programs are sets of instructions.
• Each instruction is translated into machine code (simple binary codes)
that activate the CPU (control processing unit).
• Programmers write computer code and this is converted by a
translator into binary instructions that the processor can execute.
• All software, music, documents, and any other information that is
processed by a computer, is also stored using binary.

Encoding
• Everything on a computer is represented as streams of binary
numbers.
• Audio, images and characters all look like binary numbers in machine
code.
• These numbers are encoded in different data formats to give them
meaning.
• E.g. the 8-bit pattern 11001110 could be the number 22, the
character 'XYZ', or a color in an image.

6
• Encoding formats have been standardized to help compatibility across
different platforms. For example:
• Audio is encoded as audio file formats, e.g. mp3, WAV, AAC
• Video is encoded as video file formats, e.g. MPEG4, H264 and MP4
• Text is encoded in character sets, e.g. ASCII, Unicode
• Images are encoded as file formats, e.g. BMP, JPEG and PNG
• The more bits used in a pattern, the more combinations of values
become available. This larger number of combinations can be used to
represent many more things, e.g. a greater number of different
symbols, or more colors in a picture.
Storage
• Different units of data can be used to represent the size of a file, as it
changes in size.
• Bit is the smallest unit of storage.
• The units of data increase in size from smallest to largest as:
1 𝑏𝑖𝑡 = 1/8 𝑏𝑦𝑡𝑒𝑠
1 𝑏𝑦𝑡𝑒 = 8 𝑏𝑖𝑡𝑠
Bits can be grouped together to make them easier to work with. A
group of 8 bits is called a byte.
Other groupings include:

7
Most computers can process millions of bits every second. A hard
drive's storage capacity is measured in gigabytes or terabytes. RAM is
often measured in megabytes or gigabytes.
• Computer represents all information in the form of 0s and 1s.
• A system in which information can be expressed by combinations of
the digits 0 and 1.

(If you don’t have a calculator, you can use 1000 rather than 1024.)

8
Binary and denary
• The binary system on computers uses combinations of 0s and 1s.
• In everyday life, we use numbers based on combinations of the digits
between 0 and 9. This counting system is known as decimal, denary or
base 10.
• A number base indicates how many digits are available within a
numerical system.
• Denary is known as base 10 because there are ten choices of digits
between 0 and 9. For binary numbers there are only two possible digits
available, (0 and 1). The binary system is also known as base 2.
• All denary numbers have a binary equivalent, and it is possible to
convert between denary and binary.
• Denary uses numbers with a base of 10 (uses ten digits from 0
to 9) and increases using the power of 10.
• Binary uses numbers with a base of 2 (1 and 0, 1 being on and
0 is off).
Denary place values
• Using the denary system, 8469 reads as eight thousand, four hundred
and sixty nine. One way to break it down is as:
 Eight thousands  Four hundreds  Six tens  Nine ones
• Each number has a place value which could be put into columns. Each
column is a power of ten in the base 10 system.
Thousands Hundreds Tens Ones
1000 100 10 1
(𝟏𝟎𝟑 ) (102 ) (101 ) (100 )
8 4 6 9

9
• You can also break a binary number down into place-value columns,
but each column is a power of two instead of a power of ten.
• For example, take a binary number like 0101. The columns are
arranged in multiples of 2 with the binary number written below:
Eights Fours Twos Ones
(103 ) (102 ) (101 ) (100 )
1 0 0 1

• All denary numbers have a binary equivalent and it is possible to


convert between denary and binary.
• By looking at the place values, we can calculate the equivalent denary
number.
• That is:
(1 x 8) + (0 x 4) + (0 x 2) + (1 x 1) = 8 + 1 = 9

What is binary system?


• Binary system works in base of 2.
• The only possible values are 0 or 1.
• A typical binary value is a string of 0s and 1s e.g. 11000101011000
• Computer has to translate every single instruction into Binary.
512 256 128 64 32 16 8 4 2 1
(109 ) (108 ) (107 ) (106 ) (105 ) (104 ) (103 ) (102 ) (101 ) (100 )

(In binary we can add as many zeros but still it will not change the
values like in denary.)

10
Converting binary to denary

• To calculate a large binary number like 10101000 we need more place


values of multiples of 2.
• 27 = 128
• 26 = 63
• 25 = 32
• 24 = 16
• 23 = 8
• 22 = 4
• 21 = 2
• 20 = 1
• In denary the sum is calculated as:
• (1 x 128) + (0 x 64) + (1 x 32) + (0 x 16) + (1 x 8) + (0 x 4) + (0 x 2) +
(0 x 1) = 128 + 32 + 8 = 168

11
Converting denary to binary
Method 1
• There are two methods for converting a denary (base 10) number to
binary (base 2). This is method one.
Divide by two and use the remainder
❑ Divide the starting number by 2. If it divides evenly, the binary digit is
0. If it does not - if there is a remainder - the binary digit is 1.
Worked example
Denary number 83

1. 83 ÷ 2 = 41 remainder 1 2 83
2. 41 ÷ 2 = 20 remainder 1 2 41
3. 20 ÷ 2 = 10 remainder 0 2 20
4. 10 ÷ 2 = 5 remainder 0 2 10
5. 5 ÷ 2 = 2 remainder 1 2 5
6. 2 ÷ 2 = 1 remainder 0 2 2
7. 1 ÷ 2 = 0 remainder 1 2 1

(If there is an even number like 20, 10 and 2 then we will write 0 but if
there is an odd number like 83, 41, 5 and 1 then we will write 1)
• Put the remainders in reverse order to get the final number: 1010011

To check that this is right, convert the binary back to denary:


64 32 16 8 4 2 1
1 0 1 0 0 1 1
(1 x 64) + (0 x 32) + (1 x 16) + (0 x 8) + (0 x 4) + (1 x 2) + (1 x 1) = 64 + 16
+ 2 +1 = 83

12
Worked example
Denary number 122
1. 122 ÷ 2 = 61 remainder 0 2 122
2. 61 ÷ 2 = 30 remainder 1 2 61
3. 30 ÷ 2 = 15 remainder 0 2 30
4. 15 ÷ 2 = 7 remainder 1 2 15
5. 7 ÷ 2 = 3 remainder 1 2 7
6. 3 ÷ 2 = 1 remainder 1 2 3
7. 1 ÷ 2 = 0 remainder 1 2 1
(If there is an even number like 20, 10 and 2 then we will write 0 but if
there is an odd number like 83, 41, 5 and 1 then we will write 1)
• Put the remainders in reverse order to get the final number: 1111010.
To check that this is right, convert the binary back to denary:
128 64 32 16 8 4 2 1
0 1 1 1 1 0 1 0
(1 x 64) + (1 x 32) + (1 x 16) + (1 x 8) + (0 x 4) + (1 x 2) + (0 x 1) = 122

Converting denary to binary


Method 2
• There are two methods for converting a denary (base 10) number to
binary (base 2). This is method two.
Take off the biggest second value you can
❑ Remove the second numbers from the main number and mark up
the equivalent second column with a 1. Work through the remainders
until you reach zero. When you reach zero, stop and complete the final
columns with 0s.

13
Worked example
Denary number 84
1) Set up the columns of base second numbers.
2) Find the highest second number that goes into 84. The highest
second number is 26 = 64.
3) 84 – 64 = 20. Find the highest second number that goes into 20. The
highest second number is 24 = 16.
4) 20 - 16 = 4. Find the highest second number that goes into 4. The
highest second number is 22 = 4.
5) 4 - 4 = 0.
6) Mark up the columns of base 2 numbers with a 1 where the number
has been the highest second number, or with a 0:
• Put the remainders in reverse order to get the final number: 1010100
To check that this is right, convert the binary back to denary:
128 64 32 16 8 4 2 1
0 1 0 1 0 1 0 0
(1 x 64) + (0 x 32) + (1 x 16) + (0 x 8) + (1 x 4) + (0 x 2) + (0 x 1) = 64 + 16
+ 4 = 84
Bit number patterns
• Computer systems and files have limits that are measured in bits. For
example, image and audio files have bit depth.
• The bit depth reflects the number of binary numbers available, similar
to the number of combinations available on a padlock.
• The more wheels of numbers on a padlock, the more combinations of
numbers are possible. The greater the bit depth, the more
combinations of binary numbers are possible. Every time the bit depth
increases by one, the number of binary combinations is doubled.
• A 1-bit system uses combinations of numbers up to one place value
(1). There are just two options: 0 or 1.
• A 2-bit system uses combinations of numbers up to two place values
(11). There are four options: 00, 01, 10 and 11.

14
Use binary in computer registers
• A register is a group of bits, often represented in a grid. The following
grid shows an 8-bit register.
•11011011
• When computers (or microprocessors) are used to control devices
(such as robots), registers are used as part of the control system.
• Register is a small amount of storage available as part of CPU used for
specific purpose with quick access time basically a group of bits.

Example 1
• The register could be setup as follows:
1 0 1 0 1 0 1 1
Kitchen Kitchen Kitchen Kitchen Sound Silence Send Auto
light on light off camera camera alarm alarm notification call
on off police
• In this state, the kitchen light would be triggered ON, the camera
would be triggered ON, the alarm would be triggered ON, the
notification would be sent, and the police would be auto called. When
another register is send to the control system, the state of each part
can be changed by adjusting the bits in the register.

Example 2
• A robot vacuum cleaner has three wheels, A, B and C. A rotates on a
spindle to allow for direction changes (as well as forward and backward
movement); B and C are fixed to revolve around their axles to provide
only forward and backward movement, and have an electric motor
attached:

Wheel (B)
Wheel (A)

Wheel (C)

15
An 8 bit register is used to control the movement of this vacuum
cleaner.
B Motor on 1
B Motor off 0
C Motor on 1
C Motor off 0
B Direction forward 1
B Direction backwards 0
C Direction forward 1
C Direction backwards 0
If the register contains 1 0 1 0 1 0 1 0 this means ‘motor B is ON and
motor C is ON and both motors are turning to produce FORWARDS
motion’. Effectively, the vacuum cleaner is moving forwards.
Addition of binary
0+0=0
1 1 1 1
0+1=1
0 1 0 1 1 0 1 1
1 + 1 = 10
+ 0 0 0 1 1 1 1 0 1 + 1 + 1 = 11
0 1 1 1 1 0 0 1
a bcde fg hIj k l m nopqr st uv xy za b cde fg hIj k l mnop qr st uv xy za bcde fg hIj k l m nop qr st uv xy za bcde fg hIj k l mno pqr st uv xy za bcde fg hIj k l mno pqr st uv xy za bc de fg hIj k l mno pqr st uv xy za bc de fg hIj k l mn opqr st uv xy za b cde fg hIj k l mnop qr st uv xy za b cde fg hIj k l mnopqr st uv xy za b cde fg hIj k l mnop qr st uv xy za bcd e fg hIj k l mnop qr st uv xy za bcde fg hIj k l mno pqr st uv xy za bcde fg hIj k l mno pqr s t uv xy za bc de fg hIj k l mn opqr st uv xy za bc de fg hIj k l mn opqr st uv xy za bc de fg hI j k l mn opqr st uv xy za bc de fg hIj k l mn opqr st uv xy za b cde fg hIj k l mn opqr st uv xy za b cde fg hIj k l m nopqr st uv xy za b cde fg hIj k l mnop qr st uv xy za bcde fg hIj k l mnop qr st uv xy za bcde fg hIj k l mno pqr st u v xy za bcde fg hIj k l m nopqr st uv xy z a b cde fg hIj k l mnopqr st uv xy za bcde fg hIj k l mnop qr st uv xy za bcde fg hIj k l m nop qr st uv xy za bcde fg hIj k l mno pqr st uv xy za bc de fg hIj k l mno pqr st u
v xy za bcde fg hIj k l m nopqr st uv xy za b cde fg hIj k l mnopqr st uv xy za bcde fg hI j k l mnop qr st uv xy za bcde fg hIj k l mnop qr st uv xy za bcde fg hIj k l mno pqr st uv xy za bc de f g hIj k l mno pqr st uv xy za bc de fg hIj k l mn opqr st uv xy za bc de fg hIj k l mno pqr s t uv xy za bc de fg hIj k l mno pqr st uv xy za bc de fg hIj k l mn opqr st uv xy za bc de fg hI j k l mn opqr st uv xy za b cde fg hIj k l m nopqr st uv xy za b cde fg hIj k l mnopqr st uv xy za b cde fg hIj k l mnop qr st uv xy za bcde fg hIj k l mnop qr st uv xy za bcde fg hIj k l mnop qr st uv xy za bcde fg hIj k l mno pqr st uv xy za bcde fg hIj k l mno pqr st uv xy z a bc de fg hIj k l mno pqr st uv xy za bc de fg hIj k l mn opqr st uv xy za b cde fg hIj k l mn o pqr st uv xy za b cde fg hIj k l m nopqr st uv xy za bcde fg hIj k l mnopqr st uv xy za b c de fg hIj k l mnop qr st uv xy za bcde fg hIj k l mnop qr st uv xy za bcde fg hIj k l mno pqr st uv xy za bcd e fg hIj k l mno pqr st uv xy za bc de fg hIj k l mn op
qr st uv xy za bcde fg hIj k l mnop qr st uv xy za bcde fg hIj k l mnop qr st uv xy za bcde fg hIj k l mnop qr st u v xy za bcde fg hIj k l mno pqr st uv xy za bc de fg hIj k l mno pqr st uv xy za bc de fg hI j k l mn opqr st uv xy za b cde fg hIj k l mn opqr st uv xy za bcde fg hIj k l mnopqr st uv xy za b cde fg hIj k l mnop qr st uv xy za bcde fg hIj k l mnop qr st uv xy za bcde fg hIj k l mno pqr st uv xy za bcd e fg hIj k l mno pqr st uv xy za bc de fg hIj k l mn opqr st uv xy za b c de fg hIj k l mn opqr st uv xy za b cde f g hIj k l mnopqr st uv xy za b cde fg hIj k l mn o pqr st uv xy za b cde fg hIj k l m nopqr st uv xy za b cde fg hIj k l mnopqr st uv xy za bcde fg hIj k l mnop qr st uv xy za bcde fg hIj k l mnop qr st uv xy za bcde fg hIj k l mno pqr st uv xy za bc de fg hIj k l mn opqr st uv xy z

Binary multiplication
Example of 7 (in binary 111)
7 (111 in binary) × 1 7 (111) × 2 = 14 (1110 in binary)
128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1
0 0 0 0 0 1 1 1 0 0 0 0 1 1 1 0
7 (111) × 4 = 28 (11100 in binary)
128 64 32 16 8 4 2 1
0 0 0 1 1 1 0 0

16
Binary division
Example of 20 (in binary 10100)
20 (10100) / 1 = 20 (10100) 20 (10100) / 2 = 10 (01010)
16 8 4 2 1 16 8 4 2 1
1 0 1 0 0 0 1 0 1 0
20 (10100) / 4 = 5 (00101)
16 8 4 2 1
0 0 1 0 1

• Registers contained within the CPU often have 8-bits limits on the
amount of data they can hold at any one time.
• The multiplying shifting process can cause bits to be lost at one end of
the register, and zeros added at the opposite end.
• This process is known as losing the most significant bit.

How to know that number is positive or negative?


• To represent negative numbers, it is important to think about the
place value of the furthest-left bit in a different way.
• Processor can be set up to see the bit in the eighth column as a sign
bit.
• If eight bit is 0, the number is positive and if eight bit is 1, the number
is negative.

17
Converting negative denary numbers into binary
numbers in two’s complement format
Examples: -67
 Step 1: Convert the number to positive. (67)
 Step 2: Write the number in binary form (8 bits). (01000011)
 Step 3: Invert each binary value. (1→ 0, 0 → 1) (10111100)
 Step 4: Add I to the binary number.
1 0 1 1 1 1 0 0
+ 1
1 0 1 1 1 1 0 1
 Step 5: This gives us answer as (10111101)
Summary of Convert negative denary to two's complement
 Convert to positive (+)
 Convert to binary
 Invert the digit
 Add one (+1)
 Final result

Convert negative binary numbers in two's complement


format and convert to denary
Examples: 10110011
 Step 1: Put the number into the place value column
-128 64 32 16 8 4 2 1
1 0 1 1 0 0 1 1
 Step 2: The left-most bit is 1, this means that it is negative
number.
 Step 3: Compute the denary value as usual

18
(1 x - 128) + (1 x 32) + (1 x 16) + (1 x 2) + (1 x 1)
= - 128 + 32 + 16 + 2 + 1 = - 77

Text, Sound and Image


Text representation Sound representation Image representation
Usage of the ASCII Sampling Resolution Color Depths and
Code and Unicode and Sample Rate Image Resolution

Text representation
• Every character that is input into a computer must be represented by
binary code, including the spaces we type between words and the
special characters we use for punctuation.
• It is important that computers have a common set of characters that
are recognized by a variety of systems.
• These are called character set, the most common character set are:
 American standard code for information interchange (ASCII).
 Unicode.
Unicode
• Even the extended American standard code for information
interchange (ASCII) code is not enough as it uses 8 bits so computers
began to be programmed using Unicode to represent text.
• Unicode uses 16 - bits to represent the characters in its set, which
enables over 65000 characters.

Sound representation
• Sound can also be represented by binary.

19
• For a computer to successfully process sound, the analogue signal
input has to be converted into a digital sound.
• Sound will be captured by a microphone, a piece of software will
capture it and convert the analogue to digital.
• The recording is called a sample.
Sampling used to record a sound clip
• The amplitude of the sound wave is first determined at set time
intervals.
• This gives an approximate representation of the sound wave
• Each sample of the sound wave is then encoded as a series of binary
digits.
• Increasing the number of possible values used to represent sound
amplitude also increases the accuracy of the sampled sound.
Sampling Resolution: The number of bits used to represent sound
amplitude in digital sound recording, as known as bit depth.
• A recording software is capable of taking multiple samples every
second which is measured in Hertz (Hz), where I Hz means one sample
per second.
Pros and Cons of using a higher sampling rate or larger resolution
Benefits Drawbacks
larger dynamic range produces larger file size
better sound quality takes longer to transmit/download files
less sound distortion requires greater processing power

20
Image representation
• A bitmap is literally a map of bits that form a particular picture when
rendered to a display like a computer monitor. An image is made up of
a two dimensional matrix of pixels.
• Each pixel is stored in a computer as a series of binary number.

• A black and white image only requires bit per pixel, this means that
each pixel can be one of two colors, corresponding to either 1 or 0.

• If each pixel is represented by two bits, then each pixel can be one of
four colors (00, 01, 10, 11).

21
• If each pixel is represented by three bits, then each pixel can be one
of eight colors (000,001,010,011,100,101,110,111).

Definition of color depth: the number of bits used to represent each


color is called the color depth.
Image resolution: the number of pixels that make up an image.
• Photographs with a lower resolution have less detail than those with
a higher resolution.
The Cons of using a higher resolution image
1. Increase in file size (this occurs when the number of pixel increases.
2. Greater the size, the longer it is needed to download the image.
3. A certain amount of reduction in resolution of an image is possible
before the loss of quality become noticeable.

22
Hexadecimal chapter 2
Hexadecimal
• A system of values with a base of 16. Each unit is increased by the
power of 16.
• Hexadecimal notation is closely related to binary, except instead of
using base 2 (binary) or base 10 (denary), 16 digits are used, hence base
16. There are 16 different values to be used for each 'place' in the
number.
• Because we run out of numbers to use when we get to 9 (we have
already used 0,1,2,3,4,5,6,7,8,9), we use alphabetical characters A-F to
make up the last 6 digits. Comparing denary, binary, and hexadecimal
looks like:
• It is fast and simple to convert between hexadecimal numbers and
binary.
• Hexadecimal can be used to write large binary numbers in just a few
digits which makes it easier to read, write and understand.
Denary Binary Hexadecimal
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F

23
164 163 162 161 160
65536 4096 256 16 1
• If we consider how many binary charters would represent one
hexadecimal digits, remember that 24 = 16 therefore one hexadecimal
character is equal 4 binary characters.
That is to say if four binary digits e.g. (0101) there are 16 different
numbers that can be represented by those 4 digits. It only takes one
hexadecimal digit to represent 16 different numbers, so it is equivalent.

Why is Hexadecimal?
• An 8-bit binary number can be represented by just two hex digits,
with each hex digit representing 4 bits (a nibble!).
• It is much simpler to write two digits than the full binary sequence,
saving time and effort.
• For example:
1101 0100 in binary would be d4 in hex.
F F F F 3 in hex would be 1111 1111 1111 1111 0011 in binary.

Binary to Hexadecimal Conversion


• The Binary to hex conversion process involves converting a base 2
number into base 16.
• The process for completing this conversion will be explained using the
example Binary number 11 0101 1010.
 1: The first step is to split your binary number into 4 bits (Nibbles),
so 1101011010 will become:

24
0 0 1 1
0 1 0 1
1 0 1 0
• If your binary number does not split into even groups of 4 you simply
need to add 0s to the left side until it is even. The above example adds
two 0s to change the number from 11 - 0101 - 1010 into 0011 - 0101 –
1010.
 2: The next step is to
convert each digit into a
decimal number using the
table structure below:
8 4 2 1
0 0 1 1
2+1=3
8 4 2 1
0 1 0 1
4+1=5
8 4 2 1
1 0 1 0
8 + 2 = 10
 3: Place the result from each nibble next to each other and you
have the Hexadecimal value.
• Answer = 3510 but be careful! Any number that is 10 or above 10
must be converted into its Hexadecimal equivalent.
So the answer here would be = 35A as 10 in Hex is A and 3, 5 will be
written as it is.

25
Hexadecimal to binary
• The Hexadecimal to binary conversion technique works essentially by
reversing the methods used to convert binary to hexadecimal.
• Lets imagine that we have been asked to convert FA2 (Hex) into a
binary number. These are the steps that we must follow.
 1: Separate each Hexadecimal digit and convert any letters into
their number equivalent (Use the table at the top of the page if
you need help).
This would leave us with 15(F) - 10(A) – 2
 2: The next step is to convert each separate value into a 4 bit
binary number (A nibble).
15(F) =
8 4 2 1
1 1 1 1

10(A) =
8 4 2 1
1 0 1 0

2=
8 4 2 1
0 0 1 0

 3: The final step is to put all of your nibbles together, thus giving
you the answer.
FA2 = 111110100010

26
Method 1 Decimal to Hexadecimal Conversion
 1: The first step is to convert value (203) into Binary.
128 64 32 16 8 4 2 1
1 1 0 0 1 0 1 1

 2: Now that we have the binary number 11001011, the next step
is to use the binary to hex conversion method.
8 4 2 1
1 1 0 0
8 + 4 = 12 (C)
8 4 2 1
1 0 1 1
8 + 2 + 1 = 11 (B)
203 as a Hexadecimal value = CB
Method 2 Decimal to Hexadecimal Conversion
• The second method available involves repeatedly dividing by 16 and
keeping track of the remainder.
• To demonstrate this we will use the same number as method 1 - 203.
• The first step is to set up a table with three columns with the
following headings.
Value /16 Remainder

• The next step is to place the number that you wish to convert into the
first available 'Value' row.
• Next you will move across to the '/16' column, divide the value by 16
and place the answer to 0dp (remember to always round down not up!

27
in this example 203 / 16 is 12.6875 but we still round down as we are
more interested in the remainder).
• Finally place the remainder, if any into the remainder column. If there
is no remainder you simply place a 0 in the cell.
Value /16 Remainder
203 12 11

• We now move the number in the '/16' (in this case 12) cell below the
original value of 203.
• We will repeat the steps of dividing the value by 16 and keeping the
remainder until the number in the 'value' cell is less than 16, when this
is the case we simply move the number in 'value' all the way to the
'remainder' cell and move on to the next step.
Value /16 Remainder
203 12 11
12 Value 12
• To finish the conversion we take the numbers in the 'remainder'
column starting from the bottom and working from the top. In this
case we end up with 12 and 11. Remember that in Hexadecimal, 12
Becomes C and 11 Becomes B.
203 as a Hexadecimal value = CB

28
Hexadecimal to Decimal Conversion
• To convert a hexadecimal value (Base 16) into a denary (Base 10)
number.
 1: The first step for this conversion is to create a table similar to
the one used in binary conversions.
163 162 161 160
4096 256 16 1

 2: When we have created our table headings, the next step, just
like with binary conversions, is to place our hex value (A4F3)
beneath them.
163 162 161 160
A 4 F 3

 3: Next we multiply each column heading by the hex value


beneath it.
163 162 161 160
4096 256 16 1
4096 X A(10) 256 X 4 16 X F(15) 3x1
40960 1024 240 3

 4: The final step is to add the result from each multiplication


together and we have our answer!
40960 + 1024 + 240 + 3 = 42,227 (So A4F3 = 42227)
• Represent numbers stored in registers and main memory as
hexadecimal.

29
Colors in html
• You are currently viewing this page using an internet browser that
uses a markup language called HTML (Hypertext Markup language).
• All internet browsers use HTML and convert this into webpage that
you see in front of you.
• Colors are defined in html using the hexadecimal format.
• Check this now. Look at the page source code for the browser you are
using. (Chrome - Right Click - View Source or inspect)
• Find some hex codes in the page source for this web page. These are
used as they are easier to enter and easier to read, so take less time
and effort than using binary codes.

30
MAC Address
• The Media Access Control (MAC) address is a binary number used to
uniquely identify computer network adapters.
• These numbers (sometimes called "hardware addresses") are
physically burned into the network hardware during the manufacturing
process, or stored in firmware, and designed to not be modified. They
are usually written in hexadecimal format.
• Some refer to them as "Ethernet Address" for historical reasons, but
most popular types of networks utilize MAC addressing including
Ethernet, WI-Fi and Bluetooth.
Format of a MAC Address
• MAC addresses are 12-digit (48 – bit in binary) hexadecimal numbers.
Remember that each hexadecimal numbers is 4 bits equivalent, so
4x12=48 bits. By convention, they are usually written in one of the
following format:
• MM : MM : MM : SS : SS : SS
• MM - MM - MM - SS - SS - SS
• The leftmost 6 digits (24 bits) called a "prefix" is associated with the
adapter manufacturer. Each vendor registers and obtains MAC prefixes
as assigned by the IEEE in charge of the international standards.
Vendors often possess many prefix numbers associated with their
different products. For exempla, the prefixes 00:13:10, 00:25:9C and
68:7F:74 (plus many others) all belongs to Linksys (Cisco Systems).
• The rightmost digits of ý MAC address represent an identification
number for the specific device. Among all devices manufacture with the
same vendor prefix, each is given their own unique 24-bit number.
Note that hardware from different vendors’ may happen to share the
same device portion of the Address.

31
Memory Dumps and Debugging
• Hexadecimal is often used when developing new software or when
trying to trace errors in programs.
• The contents of part of the computer memory can hold the key to
help solve many problems.
• When the memory contents are output to a printer or monitor, this is
known as a memory dump.
• A program developer can look at each of the hexadecimal codes as
shown below and determine where the error lies. The value on the far
left shows the memory location so that it is possible to find out exactly
where in memory the fault occurs. This is more manageable using
hexadecimal rather than using binary.
• It’s a very powerful fault-tracing tool, but requires considerable
knowledge of computer architecture in order to interpret the results.
Assembly Code & Machine Code
• Computer memory can be referred to directly using machine using or
Assembly Code. This can have many advantages to program developers
or when carrying out troubleshooting. Machine code and assembly
code are covered in much more detail later on in the course, but they
are essentially low-level languages that directly access the memory
chips in the computer; here we are simply interested in how
hexadecimal fits into the picture.
• Using hexadecimal makes it much easier, faster and less error prone
to write code compared to binary. Using true machine code (which uses
binary) is very cumbersome and it takes a long time to key in the
values. It is also very easy to mistype the digits in a ‘sea of 1s and 0s’.
Here is a simple example:
• STO FFA4 (assembly code)

32
A5E4 FFA4 (machine code using hexadecimal values)
1010 0101 1110 0100 1111 1111 1010 0100 (machine code using
binary)
• Machine code and assembly code are examples of low-level
languages and are used by software developers when producing, for
example, computer games.
•As you will find later, although they look cumbersome, they have
many advantages at the development stage of software writing
(especially when trying to locate errors in the code).

33
Data Storage chapter 3
• Sound (music), pictures, video, text and numbers are all stored in
different file formats.
•At the end of a computer filename is the filename extension. The
filename extension identifies the file’s format and its characteristics.
• E.g. the .doc in notes.doc indicates this is a text document.
• Proprietary file formats are file types that belong to specific software
programs or companies. The encoding methods of these file types are
often kept private, or restricted through licenses.
• The encoding methods of open format file types are published and
free to be used by everybody.
File types File formats
Sound .mp3 .wav .mid .flac .aif
Text .doc .docx .rtf .txt .pdf
Pictures .jpeg .gif .png .bmp
Videos mp4 .flv .wmv
• Midi (musical instrumental digital interface) - it is associated with the
storage of music files. Midi files are not music and don’t contain any
sounds, it is basically a communications protocol that allows electronic
musical instruments to interact with each other. The midi protocol uses
8-bit serial transmission with one start bit and one stop bit, and is
therefore asynchronous.
• Mp3 - it uses technology known as audio compression to convert
sounds and music into an mp3 format. This compression technology
will reduce the size of a normal music file by about 90%. It is
compressed by using file compression algorithms which use perceptual
music shaping, this essentially removes sounds that the human ear
can’t hear properly.

34
• Mp4 - mp4’s files are essentially the same as mp3, except that this
format allows storage of multimedia files like music, videos, and
photos.
• Jpeg - when a photo undergoes file compression, the size of the file is
reduced. One of the file formats used to reduce photographic file sizes
is known as jpeg.
• Text & number format - text and numbers can be stored in a few
different formats. Text is usually stored in an American standard code
for information interchange (ASCII) format.
Error-Checking Methods
• Parity check.
• Checks a byte of data.
• Check is performed when data is received.
• A parity bit is added (to the parity byte).
• Counts / checks number of 1’s // counts / checks to see if 1’s are even
// counts / checks to see if 1’s are odd.
• Can be even or odd. If parity is incorrect, error is detected.
Parity checking
0 0 1 1 0 1 0 1
If even was being used, the parity bit would have to be 0, as there is an
even number of 1-bits already.
1 0 1 1 0 1 0 1
If odd was being used, the parity bit would have to be 1, as there is an
even number of 1-bits already.
Before data is sent the parity bit is decided between sender and
receiver. If the sender and receiver agreed on even parity and an error
would be found if the data had odd number of first.

35
This error will be detected by the receiver as he would know that
number of first should have been 0 even.
For example look in the table below even parity is being used.
Sent:
Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 Bit 8
(parity)
Byte1 1 0 1 1 1 1 0 1
Byte2 0 0 0 1 0 1 1 1
Byte3 0 0 0 0 0 1 1 0
Byte4 1 1 1 1 0 1 1 0
(Parity) 0 1 0 1 1 0 1 0
Byte
Even parity is being used.
Received:
Bit 1 Bit Bit Bit Bit Bit Bit Bit
(parity) 2 3 4 5 6 7 8
Byte1 1 0 1 1 1 1 0 1 6
Byte2 0 0 0 0 0 1 1 1 3
Byte3 0 0 0 0 0 1 1 0 2
Byte4 1 1 1 1 0 1 1 0 6
(Parity) 0 1 0 1 1 0 1 0 4
Byte
2 2 2 3 2 4 4 2
The lower and right side boxes are the total number of ones and where
we got odd number we marked that lines as we just used even parity.
The box which is double marked is wrong.

36
The situations which parity check may not identify that a bit has been
transmitted incorrectly.
• 2 bits interchanged (e.g. 1 –> 0 and 0 –> 1) that won’t change parity
value.
• Even number of bits/digits are transposed.
• If there are multiple errors in the same byte/column, that still
produce the same parity bit, the error will not be detected.
Checksum
• It is an error detection method that sends an additional value with
the original data.
• This additional value is known as the checksum.
• It is a fixed-length modular arithmetic sum of the message. E.g. a
byte.
• To understand how it works, assume the checksum is 1 byte in length
i.e. the max value can be 2^8 - 1 = 255.
• The sum for the bytes is calculated.
• This value is then transmitted with the block of data.
• At the receiving end, the checksum is re-calculated from the block of
data received.
• The calculated value is then compared to the checksum transmitted.
• If they are the same value, then the data was transmitted without any
error.
• If the values are different, then an error has been found.
• If the values are different, then a request is sent for the data to be re-
transmitted.

37
• <= 255:
• If the sum of all the bytes transferred is less than or equal to 255 then
checksum will be this value 2^8 - 1 = 255.
• >255:
• If the sum of all the bytes transferred is greater than 255 then
checksum will be calculated using the following method.
Divide the sum (x) of the bytes by 256  round the value to nearest
whole number (y)  multiply the value (y) by 256 (z)  calculate the
difference (x-y).
• Example:
• Suppose the sum of the bytes is 1185.
• Since it is greater than 255 therefore, we will use the second method.
• First, 1185 will be divided by 256. i.e. 1185/256 = 4.496.
• Round this value to the nearest whole number i.e. 4.496 rounds off
to 4.
• Multiply the rounded value to 256 i.e. 4 × 256 = 1024.
• Calculate the difference i.e. 1185 – 1024 = 127 checksum.
Note:
• When data is to be transmitted, its checksum is calculated and
attached to the original message before the transmission.
• At the receiving end, the checksum of the received block is again
calculated and compared with the transmitted checksum.
• If both checksums are the same, then the data is error-free.

38
ARQ (Automatic Repeat Request)
• Uses acknowledgment and timeout.
• A request is sent with data to acknowledge all data is received.
• Acknowledgement sent back to say all data is received.
• If no acknowledgement is received in a time frame an error in
transmission detected.
• And the data automatically resent.
Echo (check)
• Copy of data is sent back to sender.
• Data is compared to see if it matches.
• If it does not match then error detected.
• It can’t tell if the data got corrupted at receiving or sending end.
Check digit
• It is an error detection system in which an additional number is added
to the series (e.g. account no. etc.) to check the accuracy.
• This number is usually derived from the original series of numbers.
• For example, consider a number 232, the sum of these three digits
(2+3+2=7) can be added as the last digit to the original series i.e. 2327.
Check digit are used to ensure accuracy of entered data.
A 7-digit number has an extra digit on the right, called the check digit.
Digit position 1 2 3 4 5 6 7 8
Digit _ _ _ _ _ _ _ _

Check digit

39
The check digit is calculated as follows:
• Each digit in the number is multiplied by its digit position.
• The seven results are then added together.
• This total is divided by 11.
• The remainder gives the check digit. (If the remainder = 10, the check
digit is x)
Example Consider an ISBN-10 number 0 - 2 0 1 - 5 3 0 8 2 - X that is
typically used on books that use the module 11 system
• To calculate the value of X, first, we need to find out the placement of
each digit.
Digit 10 9 8 7 6 5 4 3 2 1
position
Number 0 2 0 1 5 3 0 8 2 x
• Multiply each digit with its position.
• (0 x 10) + (2 x 9) + (0 x 8) + (1 x 7) + (5 x 6) + (3 x 5) + (0 x 4) + (8 x 3) +
(2 x 2)
• = 0 + 18 + 0 + 7 + 30 + 15 + 0 + 24 + 4
• = 98
• Divide the total with 11,
98/11
= 8 remainder 11
• Check the difference, i.e. subtract X placement from the remainder.
11 – 10 = 1
• This value is your check digit and the final ISBN becomes,
Number 0 2 0 1 5 3 0 8 2 1

40
MIDI
• Musical Instrument Digital Interface is a widely-used standard for
interconnecting electronic musical instruments and computers.
• Its associated with the storage of music files. However, the MIDI files
don’t contain any sound.
• This makes them much smaller than other music file types.
• MIDI uses 8 bit, asynchronous serial transmission, which means that
there is a start bit and stop bit.
• A MIDI file consists of a list of commands instructing which note to
play and how loud. MIDI has 16 channels.
•A MI D I file consists of a list of commands that instruct a device (for
example, an electronic organ, sound card in a computer or in a mobile
phone) how to produce a particular sound or musical note.
•. MIDI operates on 16 different channels, which are numbered O to
15.
• Note on/off: this indicates that a key (on an electronic keyboard) has
been pressed/released to produce/stop producing a musical note
• Pressure: this indicates how hard the key has been pressed (this could
indicate loudness of the music note or whether any vibrato has been
used, and so on)
• Two additional bytes are required, a PITCH BITE, which tells the MID I
device which note to play, and a VELOCITY BYTE, which tells the device
how loud to play the note.
•When music or sound is recorded on a computer system, these MIDI
messages are saved in a file which is recognized by the file extension
.mid.

41
JPEG:
• When a photographic file is compressed, the size of the file is
reduced.
• However, the quality of the image is sacrificed for this reduction of
size. Once an image is compressed, a new file is created which replaces
the original file.
• Joint Photographic Experts Group will reduce raw bitmap image by a
factor of 5 – 15 (depending on the quality of the image).
• A camera raw image file contains minimally processed data from the
image sensor of either a digital camera, a motion picture film scanner,
or other image scanner. Raw files are named so because they are not
yet processed and therefore are not ready to be printed or edited with
a bitmap graphics editor.
• The file size of an image is determined by the number of pixels as well
as the number primary colors the image uses.
• Most images use three primary colors: red, green and blue.
• The number of pixels of an image is calculated by the length x width.
e.g.: an image which is 1000px by 2000px:
So, 1000 x 2000 = 2,000,000px
So the file size of that image would be: 2,000,000 x 3 (3 because 3
primary colors)
= 6,000,000 bytes
= 5859.38 kilobytes
= 5.72 megabytes
E.g. an image is 128 by 364 pixels:
= 128 x 364 = 46,592px

42
•Calculate the size of the file:
46,592 x 3(primary colors)
139,776 bytes
= 139,776 / 1024 = 136.5 kilobytes
• Calculate the size of the JPEG file when it’s reduced by a factor of 7:
136.5 / 7
= 19.5 kilobytes
Comparison of mp3 and midi
MP3 MIDI
 Digital recording of  Instructions of how to make
sound. sound.
 Produced by recording  Non-audio recording.
software/microphone.  File created using digital
 Used when distributing musical instruments.
sound files.  Produced by synthesizer.
 Compressed file format.  Used when composing music.
 Individual notes/instruments
can be changed.

MP3
• MP3 is a technology that compresses music files. (It is also known as
audio compression.) (It compresses a typical music file by almost 90 %.)
• E.g. A100 MB music file can be converted into an MP3 file format with
a size of 10 MB.
• These types of files can be used in cellphones, computers or MP3
players.

43
• The music files are compressed using a technology known as
‘Perceptual Music Shaping’.
• This technology removes the sounds that the human ear cannot hear
meaning that compression is done by removing some part of the music
without affecting the overall quality of music.
• It uses a lossy Format for compression.
Same points but in more detail
• A file extension and compression method that utilizes the mpeg standard
(lossy)
• To reduce the size, often by a factor of 12, while still maintaining audio
quality
• MP3 files are commonly used to store the whole cd and require less drive
space
• MP3 files are, on average, 90% smaller than the music files stored on a cd
• Flac is a lossless audio format uses audio compression technology to
convert sound into a MP3 format.
• This reduces the size of a normal sound file by around 90% (so a factor of
10)
• ForCalculate
MP3 example, how
an 80-megabyte
much spacesound
the file
CD could
wouldbeneed
reduced to an 3
to store 8 tracks
megabyte MP3 file.
which are 3, 6 and 7 minutes long.
This is done by removing sounds that humans can’t hear (perceptual music
shaping)
=3 + 6 + 7 = 16 minutes
=16
e.g.: Music is to be stored on xa 12
CD.=Each
192minute
megabytes
of music is worth 12
megabytes.
e.g.: Calculate how much space the CD would now need.
(You may assume the file size is reduced by 90%)
192 x 0.1 = 19.2 megabytes
e.g.: The CD has 800 megabytes of space.
Calculate how many minutes can be stored on the CD.

44
MP4
• It’s a compressed video format (lossy) that also can store audio and
images.
• MP4 file extension is an mpeg-4 video file format.
• MP4s are one of the more common video file formats used for
downloading and streaming.
Compression
• Compression is used to reduce file sizes – something which is
essential in an era of online video streaming and media sharing.
•Without compression, we would:
• Fit less music, videos or photos onto your smart phone or computer.
• Struggle to stream or download videos from the internet.
• Struggle to upload media to the internet.
• Find browsing websites a slower experience.
Lossy and Lossless
• Lossy - The file compression algorithm eliminated unnecessary bits of
data and cannot return to its original state when uncompressed.
• Lossless - All the data bits from the original file are reconstructed
when the file is again uncompressed. This is important for files where
loss of any data will be disastrous, e.g. a spreadsheet file.
Text File Compression
“LIVE AS IF YOU WERE TO DIE TOMORROW, LEARN AS IF YOU WERE TO
LIVE FOREVER”
This sentence consists of 74 memory units To compress this, a
compression algorithm can use a data dictionary to store repeated

45
groups of characters The data dictionary can store these groups and
replace the ones in the text with numbers:
LIVE -> 1
AS IF YOU WERE TO -> 2
OR -> 3
1 2 DIE TOM3ROW, LEARN 2 1 F3EVER.
Now this new sentence is now 34 memory unit.
This has saved 54% of the original file size.
When the file is uncompressed, the groups of characters in the data
dictionary are fetched and replace the numbers in the sentence.
Advantages of compressing a file
• Smaller file size to transmit.
• File is transmitted faster.
• Requires lesser bandwidth.
Types of Data Storages:
• There are two types of data storages i.e. primary and secondary.
• The primary storage retains data in RAM (Random Access Memory),
ROM (Read Only Memory), or cache.
• The secondary storage stores data in hard disks, RAID (Redundant
Array of Independent Disks Systems), Zip drivers, etc.
• Primary storage is faster to access whereas secondary storage can
store more data.
• Primary storage is also known as Main Storage whereas Secondary
Storage is also known as Auxiliary Storage.

46
Data Transmission (Communication & Internet
technologies) chapter 4
Transmission of data
• It can be defined as the movement of data from one device to
another in the form of bits.
• To transfer data, some form of medium is required e.g. fiber optics,
etc.
• Data can be transferred over a short distance i.e. from computer to
printer or over long distance i.e. overseas call via phones.
• Three major factors are required to be considered for the transfer of
data:
• 1. Data transfer direction (one way or two way). (1. Simplex, 2. Duplex
and 3. Half-Duplex).
• 2. Transmission method i.e. no. of bits to be transmitted in one time.
(Serial or parallel).
• 3. Synchronization method. (Synchronous or asynchronous).
Synchronous and Asynchronous
• Synchronous data transmission is a data transfer method in which is a
continuous stream of data signals accompanied by timing signals. It
helps to ensure that the transmitter and the receiver are synchronized
with each other.
• This communication methods is mostly used when large amounts of
data needs to be transferred from one location to the other.
• Asynchronous data Transmission is also known as start/stop
transmission, sends data from the sender to the receiver using the flow

47
control method. It does not use a clock to synchronize data between
the source and destination.
• This transmission method sends one character or 8 bits at a time. In
this method, before the transmission process begins, each character
sends the start bit. After sending the character, it also sends the stop
bit. With the character bits and start and stop bits, the total number of
bits is 10 bits.
• Synchronous is a data transfer method in which a continuous stream
of data signals is accompanied by timing signals whereas Asynchronous
data transmission is a data transfer method in which the sender and
the receiver use the flow control method.
Types of Data Transmission
• There are two types of data transmission:
• 1. Serial
• 2. Parallel
Serial Data Transmission
• In serial communication systems, there is a single wire over which
data bits are transferred one by one.
• It is known as serial transmission because bits need to be organized
before they are sent over the channel.
• This way the receiver can receive and arrange data in order and
consider it to be errorless.
• This data transmission is best utilized when communication needs to
be done over long distances.
• The data transmission speed in serial communication systems is
slower compared to parallel communication systems.
• In serial data transmission, there is no issue of synchronization.

48
Parallel Data Transmission
• In parallel communication systems, there are multiple lines of wires
and data is transmitted simultaneously over these parallel wires.
• This data transmission method can be best utilized over short
distances.
• If used over a long distance the synchronization issue can occur i.e.
the bit can become skewed.
• It is used usually for internal communication in computer systems.
• It is faster as compared to serial data transmission.

49
Difference in between Serial transmission and parallel
transmission

Modes of Data Transmission


• There are three modes of data transmission:
• 1. Simplex
• 2. Duplex
• 3. Half-
Duplex

50
Simplex Data Transmission
• In this mode, data is transmitted in one direction only i.e. sender to
receiver.
• Example:
• Transfer of data from computer to printer.
Duplex Data Transmission
• In this mode, data is transmitted in both directions simultaneously
• Example:
• Broadband phone connection and phone calls.
Half-Duplex Data Transmission
• In this mode, data is transmitted in both directions but not
simultaneously i.e. not at the same time.
• Example:
• A phone conversation like walkey talkies the security teams use.
Error Detection & Correction in Data Transmission
• In data transmission, during the transfer of data, noise and other
impairments are introduced; the methods used for the detection of
these is known as error detection.
• Error detection helps in data’s reliable delivery across channels.
• It also helps in reducing the undetected error probability i.e. the
transfer of incorrect frames.
• Some kind of algorithm is applied before the transmission of data to
produce an error-detection code that is usually sent over the channel
with the data.

51
• The receiver applies the same algorithm and generates error code
from the received data then compares it with the error code generated
at the sender’s end.
• If both codes are the same then it means the data received is error
free.
• Otherwise, the received data is considered incorrect and the receiver
acts accordingly.
How Parity Bit Are Used For Error Detection
• Data transfer also encounters noise and impairments that alter the
digital signal.
• E.g. data sent 1001 can be received as 1101.
• To detect this type of error, the parity bit can be used.
• Parity bit system can be even or odd and it is the introduction of one
additional bit at the start or end of the bit stream to transmit.
• In even parity system, the number of occurrences of 1s needs to be
even and decide whether parity bit should be 0 or 1.
• However, in an odd parity system, the number of occurrences of 1s
need to be odd and decide the value of the parity bit.
Example:
• Consider, the data to be transmitted in 1001001 and uses an odd
parity system, so the parity bit will be 0 since the number of
occurrences of 1s is already odd.
0
parity 1 0 0 1 0 0 1
bit
• Now suppose this data with the parity bit is transferred, and the
receiver knows that the parity system used is odd.

52
• The received data block has encountered noise and altered to,
0
parity 1 0 0 1 0 0 0
bit
• In this case, the parity bit will help the receiver detect an error since it
no longer corresponds to the odd number of occurrences of 1s.
• The parity bit only helps in detecting 50% of the errors.
• However, in parity detection, there is a shortcoming that it cannot
detect the error if more than 1 bit has been altered, e.g.
0
parity 1 0 0 1 0 1 0
bit

Integrated Circuit (IC)


• In the initial time, data was sent in serial form i.e. one bit at a time
over a single channel.
• With the advent of technology, Integrated Circuit (IC) introduced and
allowed multiple devices on a single silicon chip.
• Because of it, the parallel transmission of data came into existence.
• Conventionally, it uses the transfer of a byte (8-bit) simultaneously
making the transfer of data faster.
• The standard parallel interface uses a 36-wire heavy cable that was
also expensive.
• Today, many ICs make use of serial and parallel data transmission.
Example:
• Multiplexer or ‘MUX’ is an example of an IC that utilizes both serial
and parallel interface.

53
• It is a combinational logic circuit.
• It is used to switch multiple input signal lines to a single output line
using a control signal.
• It works as a multiple position rotatory switch i.e. very fast.
• The input lines are also known as channels.
• It can be digital using logic gates or analogous using transistors, relays
or MOSFET.
• Communications between devices such as computers and printers
and across networks is performed adequately with serial lines. Data
transmission over much shorter distances inside integrated circuits (ICs)
is best done using parallel channels. ICs usually employ three buses for
communication:
• Data bus: carries data between memory and processor and also
between ports and other parts e.g. sound card, graphics card, have own
processors and memory and some data are moved to processor and
main memory; bi-directional (duplex), data flow to processor and back
to memory.
• Address bus: carries address from processor to location in main
memory (some ports may be memory-mapped so have addresses too);
unidirectional, no need for an address to flow back to processor.
• Control bus: carries signals from processor to parts of CPU and
system to activate something e.g. to read or write data to a memory
location or I/O device.
• Integrated Circuits or an IC is defined as a microchip on which
thousands and hundreds of electrical components, such as resistors,
capacitors and transistors, are fabricated.
• An IC functions as an oscillator, amplifier, microprocessor and timer
or as computer memory.

54
Universal Serial Bus (USB) (this is more for your knowledge)

• It uses an asynchronous method for data transmission.


• It has been widely used today for the transfer of data from the
computer to multiple devices.
• USB cable typically consists of four-wire shielded cable; two used for
data transfer and the other two used for power and earth.
• USB is detected automatically by the computer system.
• The device is then recognized and the required driver is installed
automatically.
• Around 127 devices can be connected to a single USB port using a
USB hub.
Serial uses Parallel uses
USB CPU
Fire wire ATA/IDE
PCL-E
Telephone

55
Internet Principles of Operation chapter 5
Internet Principles of Operation
• The Internet can be defined as the interconnection of computer
systems.
• It utilizes the TCP/IP protocol. TCP/IP stands for Transmission Control
Protocol/Internet Protocol and is a suite of communication protocols
used to interconnect network devices on the internet.
• It can be accessed using 3G, modem, broadband, etc.
• The Internet is accessible to everyone worldwide and contains billions
of web pages and tons of information.
• Information on the web (internet) can be accessed via a search
engine.(Google, Microsoft Bing, Yahoo.)
• Hyperlinks are used to browse webpages whereas files (video, audio,
text, etc.)can be retrieved or shared by downloading and uploading
respectively.
• Today, the internet is also widely used for communication purposes.

Working of the Internet


• The TCP/IP protocol makes the retrieval and transmission of
information possible.
• When you send a request it goes through the network to the DNS
(domain name servers).
• The DNS then points the request in the right direction and it reaches
its targeted server.

56
• Once the request has been received by the server, it can send back a
response to the computer system that sent the request.
• The response sent by the server can take a completely new path.
• The internet is a powerful tool and one major reason for it is its
flexible approach to data transfer.

Browser
• It is a web application that enables internet users to access various
web pages.
• It is responsible for translating the basic HTML code to allow internet
users to see videos, images, audio, hyperlinks, etc.
• When a user enters a URL in the browser, it requests the web server
for the information, the web server then displays the requested
information on the computer screen in a browser application.
• The most commonly used browsers are as under: - Mozilla Firefox -
Google Chrome - Internet Explorer – Safari.
• You can either go to a webpage by directly entering the URL if you
know it or you can click on links n different webpages to navigate to
your desired web page e.g. use of a search engine like Google.
Typical Features of a Browser Toolbar
• It has a ‘Home’ button that allows you to go to the first page that you
started off with the internet.
• It has a ‘Bookmark’ or ‘Favorite’ feature that allows you to save
webpages to access them immediately later.
• It also allows you to directly print web pages.
• It allows you to track, monitor or remove your web history.

57
• It allows you to go to a previous page using the ‘back’ button or go
forward.

Internet Servers
• The machines on the Internet can be divided into two types i.e. clients
and servers.
• Servers are machines that provide services to other machines such as
FTP servers etc.
• On the contrary, clients (user machines) are the machines that are
connected to get these services offered by servers.
• For example, if you use Google to search your query you are using
your machine which acts as a client whereas Google has multiple
machines that are fulfilling your request and acting as a server.
• Any machine can be a ‘server’ or a ‘client’ or ‘both’.

Internet Service Provider (ISP)


• Internet Service Provider (ISP) can be defined as a company that
provides the Internet connection to businesses and individuals.
• ISP generally takes a monthly fee to provide an internet connection.
• The monthly fee is usually based on the speed of the internet as well
as the bandwidth provided.
• The Internet Service Provider usually sets up a user account with a
password and username.
• Some ISPs also offer web building, emails, hosting, etc.
• ISPs have become common in the 1990s prior to that Internet access
was limited to government agencies and universities etc.

58
Hypertext Transfer Protocol (Http)
• The Http or Hypertext Transfer Protocol as its name suggests is a
protocol i.e. used for transmitting messages or data files over www
(World Wide Web).
• Any protocol can be defined as a set of rules.
• When you browse websites using the browser you are in fact using
this protocol.
• Today, you might notice the use of https more than Http.
• Https is actually the secure and encrypted version of this protocol.
• It is a crucial protocol when browsing websites and it cannot be
ignored.
• Beside it, another important protocol is HTML that deals with the
formatting and display of the webpages.

Http identifies the following methods to understand the


required action
• HEAD - without the response body, it asks about the GET request The
HEAD method is used to ask only for information about a document,
not for the document itself.
• GET - request with a response body the specified source presentation
difference between HTTP HEAD and GET requests is that for HTTP
HEAD, the server only returns headers without body.
• POST - submits data to convert it from HTML to the identified source
form.
• PUT – it uploads specified source’s representation.

59
• DELETE – removes the source specified.
• TRACE – allows the user to see changes by servers to the specified
request by echoing it back.
• OPTIONS – it checks web servers functionality for a specified URL by
returning HTTP methods. (The HTTP OPTIONS method is used to
request information about the communication options available for the
target resource.)
• CONNECT – it converts the connection to TCP/IP tunnel to provide
encrypted communication by facilitating SSL (secure socket layer) via an
unencrypted Http proxy.

HTML Structure and Presentation


• HTML (Hypertext Markup Language) is the language used to create
web pages.
• The browser is responsible for the interpretation of HTML pages.
• There are two types of HTML; structure and presentation.
• The HTML structure is responsible for defining the structural markup
as well as the semantics of the HTML pages.
• Whereas, what we see in the web browser is called HTML
presentation i.e. multimedia use and appearance.
• The HTML presentation is also known as ‘style’.
• Both HTML structure and presentation should be written separately
i.e. the developer should have an HTML doc and a CSS (Cascading Style
Sheet) that deals with the presentation of the webpage.

MAC Addresses
• It stands for Media Access Control Addresses.

60
• It is a 48-bit (6 hex-digit groups) unique value that helps in the
identification of the actual device on the internet.
• The MAC address remains the same even when you connect to the
internet from any location.
• It can be found inside your device’s NIC (network interface card).

IP Addresses
• It stands for Internet Protocol Addresses.
• It a unique identifier that every device on the internet has.
• It represents the device location and allows these devices to
communicate over the internet.
• Without IP addresses, accurate data communication and transfer over
the internet will not be possible.
• An IP address is assigned to your device by ISP/network when you
connect to the internet for a session.
• An IP address is like a home address that helps in the successful
delivery of packages.
• Therefore, contrary to the MAC address, IP addresses change each
time your device is connected to the internet.
• Example of an IP Address 10.10.10.10

61
URL:
• It stands for Uniform Resource Locator.
• It is an address that allows the World Wide Web to identify and load
the requested web page in the browser.
• A URL has three parts; https:// is the access protocol,
www.amazon.com is the domain name and anything written after that
will be the path or file name.
• If nothing is written then it will take you to the homepage of the
website.

Uses of Cookies
• To maintain and store on a website, user preferences.
• To collect user behavior analytics.
• To store shopping cart items.
• To show relevant ads.

62
Computer Architecture & the fetch-execute
cycle chapter 6
Von Neumann Architecture:
• Von Neumann Model is the most common architecture
representation of a computer system.
• In 1945, it was published by John von Neumann.
• The Von Neumann architecture includes Arithmetic & Logic Unit
(ALU), Control Unit (CU), Memory Unit, Inputs/Outputs (I/O) and
Registers.
• John von Neumann’s idea is based on holding data and programs in
read-write Random Access Memory (RAM) and then transferring it to
the Memory Unit and processor i.e. the idea of a stored program.
• Before the introduction of stored programs, data and programmed
instructions were stored separately.
• Von Neumann’s idea to treat programmed instructions as data has
made many programming tools possible including assembler and
compiler.
• Figure (i) shows a basic Von Neumann's architecture representation
that shows the connection between processor and memory with buses.
• Figure (ii) is a more detailed representation of a Von Neumann
architecture and introduces the concept of registers and addresses.

63
Figure below Basic Von Neumann's Architecture
Figure (i)

Figure below Detailed Von Neumann's Architecture


Figure (ii)

64
Central Processing Unit (CPU)
• The CPU is responsible for executing instructions.
• It includes the Control Unit, Arithmetic and Logic Unit, and various
registers.
1. Arithmetic and Logic Unit:
• It responsible for carrying out the logic operations (OR, AND, NOT,
XOR, etc.) and arithmetic operations (add, multiplication, subtract,
etc.).
2. Control Unit:
• It is responsible for controlling the operations of the Arithmetic and
Logic Unit (ALU), Memory Unit and I/O devices.
• It tells the devices, how to respond to programmed instructions after
interpreting the instructions from the memory unit.
3. Registers:
• In the CPU, there are high-speed storage areas known as registers.
• Before data is processed, it first must be stored in a register.
• In Figure (ii), you can see various types of register. The details of some
registers are as under:
Registers Full form Function
CIR Current Instruction During processing, it contains the
Register. current instruction.
AC Accumulator. Logic and arithmetic intermediate
results are stored here.
MDR Memory Data It holds data that needs to travel from
Register. & to memory.

65
PC Program Counter. The next executable instruction's
address is stored there.
MAR Memory Address The memory location of data is stored
Register there, that needs to be accessed.
Fetch-Execute Cycle
• It is also known as the Fetch-Decode-Execute cycle.
• It is the basic operations (instructions) cycle of a computer system.
• During this cycle, programmed instruction is retried from the memory
and then the required actions are performed as per the instructions.
• While the computer system is ON, the fetch-decode-execute cycle is
repeated continuously.

Steps of the Cycle


 Fetch:
1. PC (Program Counter) contains the next instruction address.
2. The address in PC is loaded in MAR (Memory Address Register).
3. Lookup for MAR and copy instructions data into MDR (Memory Data
Register).
4. Copy data from MDR to CIR (Current Instruction Register).
 Execute:
5. Increment the Program Counter by 1.
6. Decode the instructions data available in CIR.
7. Execute the instruction.
 Reset:
8. Reset (repeat from step 1).

66
The program counter (PC) This address is then
contains the address of copied from the PC to the
the memory location of memory address register
the next instruction (MAR); this is done using
which has to be fetched the address bus.

The contents The contents (instruction) at


(instructions) of the MDR the memory location (address)
are then copied and contained in MAR are then
placed into the current copied temporarily into the
instruction register (CIR). memory data register (MDR).

The value in the PC is The instruction is finally decoded


then incremented by 1 and then executed by sending
so that it now points to out signals (via the control bus)
the next instruction to the various components of
which has to be fetched. the computer system

Buses
• It allows the transmission of data from one part to another part of a
computer system.
• It provides a connection from internal components to memory and
processor.
• A typical CPU is comprised of the following three types of buses:
 Address Bus
• It is responsible for transmitting the data addresses between memory
and processor.

67
• It does not transmit the data, only the addresses.
 Data Bus
• It is responsible for transmitting the data between the memory unit,
processor and the I/O devices.
 Control Bus
• It is responsible for transmitting the control commands/signals from
the CPU in order to coordinate and control all activities within the
computer system.
• It also carries the status signal from other devices.

68
Logic Gates chapter 7
Logic Gates
• Logic gates take binary inputs and produce a binary output.
• The values it deals with are 0 and 1 or on and off.
• The binary states are the electrical voltage states, i.e. 0 represents an
ON state and 1 represents an OFF state.
• Multiple logic gates are used to create a logic circuit.
• Logic gates are a crucial element of a logic circuit.
• Different logic gates have different characteristics.
• Truth Tables are used to verify the outputs of the logic gates.

Six (6) Types of Logic Gates

69
Six (6) Types of Logic Gates
1. NOT Gate
• NOT Gate is the most simple logic gate.
• It takes a single input and inverts the value.
• If an input is 0, NOT will make it a 1 and vice versa.
• It is represented by 𝐴.
 Logic Notation: X = NOT A
 Boolean algebra 𝑋 = 𝐴.
Truth Table
In put Out put
0 1
1 0

2. AND Gate
• AND Gate produces ‘1’ as an output only and only if all inputs are ‘1’.
• If anyone input is '0' then the result will be '0'.
• It is represented by A.B.
 Logic Notation: X = A AND B
 Boolean algebra 𝑋 = 𝐴. 𝐵
Truth Table
In put 1 In put 2 Out put
0 0 0
0 1 0
1 0 0
1 1 1

70
3. OR Gate
• OR Gate produces ‘1’ in output if a single input is 1.
• It produces a ‘0’ in output only if both inputs are ‘0’.
• It is represented by a ‘+” sign.
 Logic Notation: X = A OR B
 Boolean algebra 𝑋 = 𝐴 + 𝐵
Truth Table
In put 1 In put 2 Out put
0 0 0
0 1 1
1 0 1
1 1 1

4. NAND Gate
• It is also known as the NOT AND Gate.
• It is the reverse of AND Gate.
• It gives ‘1’ in output if and only if any one or both of A and B both are
‘0’.
 Logic Notation: X = A NAND B
 Boolean algebra 𝑋 = 𝐴. 𝐵
Truth Table
In put 1 In put 2 Out put
0 0 1
0 1 1
1 0 1
1 1 0

71
5. NOR Gate
• It is also known as NOT OR Gate.
• It is the reverse of OR Gate.
• It produces ‘1’ in output if NOT a single input is 1.
 Logic Notation: X = A NOR B
 Boolean algebra 𝑋 = 𝐴 + 𝐵
Truth Table
In put 1 In put 2 Out put
0 0 1
0 1 0
1 0 0
1 1 0

6. XOR Gate
• It is also known as Exclusive OR Gate.
• It produces ‘1’ in output if, (A is ‘1’ AND B is ‘0’) OR (A is ‘0’ AND B is
‘1’).
 Logic Notation: X = A XOR B
 Boolean algebra 𝑋 = (𝐴. 𝐵)(𝐴. 𝐵)
Truth Table
In put 1 In put 2 Out put
0 0 0
0 1 1
1 0 1
1 1 0

72
Summary of logic gates

73
Logic Circuits
• Logic circuits are created by connecting logic gates together.
• These circuits are created to perform a particular function.
• A logic circuit truth table is required to understand its function’s
nature.

How to Create a Logic Circuit Truth Table


• It is considerably complicated to create a logic circuit truth table.
• But if you follow the steps defined below, it will become easy for you
to make it yourself.
• Don’t overdo yourself by trying to do everything in your head.
Steps

74
1. First, add temporary output letters after each logic gate in a circuit as
shown above.
2. Now find out the values of these new letters first i.e. K, L & M.
3. As you can see from the figure, that K is NOT A.
4. L is the output of A OR B.
5. M is the output of K AND L.
6. And the final output will be M or L.
7. This can also be written in the equation as
𝑋 = (𝐴 . (𝐴 + 𝐵)) + (𝐴 + 𝐵)
8. Therefore, it is advisable to solve in the same sequence and you will
get your truth table easily.
Input A Input B K L M Output X
A N 𝑨 A+B K.L L+M
0 0 1 0 0 0
0 1 1 1 1 1
1 0 0 1 0 1
1 1 0 1 0 1

• Note: Just as you can make a Boolean equation by seeing the logic circuit you can also
create a logic circuit from the equation.

75
Input Devices chapter 8
Input Devices
• Input devices can be described as the peripheral devices that we use
to send out signals to the computer system.
• A computer system can not do the processing without receiving some
input from the user.
• Therefore, these devices are used to send raw data for processing to
the system.

Types of Input Devices


• Input devices are of two types:
 Manual Input Device – Devices like keyboard, mouse, and scanner
are manual devices that require the user to manually input the
data for processing.
 Direct Data Entry Devices (DDE) – Examples include smart cards,
optical mark recognition, etc. These devices automatically transfer
the data from the source file (e.g. barcode) to the computer
system.

Different Input Devices


• Mouse • Touchscreens
• Keyboard • Microphone
• Concept Keyboard • QR Code Reader
• 2D & 3D Scanner • Digital Camera
• Trackball • Interactive Whiteboard
• Graphic Tablets • Barcode Reader

76
1. Mouse
• It can be wireless or wired and allows the user to control the
cursor/pointer’s movement on the screen.
• The user can control the cursor coordinates or movement by moving
it over a flat surface.
• The mouse has two to three buttons.
• With the mouse, objects can be clicked/moved, folders can be
opened by double-clicking or options of a folder/application can be
seen by using the right-click button.
• Today, the mouse has become optical i.e. it uses a laser to track the
movement however, in the past mouse used to have a small ball inside
them for the tracking.

Advantages and disadvantages of mouse


Advantage Disadvantage
• Simple and fast at inputting • Needs a flat surface to move the
commands. mouse.
• Navigate easily around a screen. • If dirt covers roller ball or laser,
it can stop the mouse from
working properly.
• Hard for people with physical
disabilities.
•Doesn't use text.

77
2. Trackball
• Besides mouse, a trackball is also an input device i.e. used to control
the cursor movement on the screen.
• However, the user keeps the trackball at one position and only moves
the ball within it for movement control.
• The trackball is best for users with limited hand motor skills and some
people prefer it as it gives great control over the movement without
demanding a lot of space to use it.
• Mouse and Trackball are also known as pointing devices.

3. Keyboard
• It can be wireless or wired.
• It is an input device that allows the user to enter commands or data
by pressing keys.
• When a user presses a key, an ASCII code is sent to the computer
system.

78
• A keyboard contains over 100 keys that can be divided into four
groups/categories.
• Function keys: contains twelve function keys from F1 – F12 that
perform special functions.
• Numeric keys: contains numeric digits 0 – 9, arithmetic signs of plus,
multiplication, division, subtraction, and a decimal point.
• Cursor keys: contains arrows for left, right, down and up.
• Main Keyboard: contains the alphabets, special characters, etc.

Advantages and disadvantages of key-board


Advantage Disadvantage
• Simple. • Easy to make a mistake.
• Efficient when user types fast. • Only one letter typed at a time.
• If person is not trained on using
the keyboard, it can be very slow.

4. Concept Keyboard
• A concept keyboard is a keyboard that has keys that are programmed
to perform special tasks and have visual images on them instead of
letters/characters/numbers.
• For example, a restaurant counter representative may have this
keyboard with different meal button, etc.

79
• Today, these keyboards are replaced by virtual concept keyboards or
touchscreens.

5. Microphone
• The microphone is like a transducer i.e. it converts energy from one
form to another.
• It is used to take analog sound waves as an input.
• It then converts the sound waves into electrical signals that the
computer system can understand.
• There are different types of microphones available, but they all have a
diaphragm.
• A diaphragm is a piece of paper, aluminum, etc. that vibrates when a
person speaks into the microphone.
• These vibrations are then converted into electrical signals.

80
6. Digital Camera
• It is used to capture images/videos by sampling light from by time,
spatially and tonally, and store on a memory card.
• Spatially: sampling the angle of view into a rectangular grid of pixels.
• Tonally: sampling the varying tones of brightness.
• Time sampling: exposure of a given duration.
• Unlike the traditional camera, a digital camera uses an image sensor
made of silicon that is sensitive to light.
• Digital cameras also contain a display screen with options to change
settings.
• The display screen also allows the user to view the captured
image/video.

Advantages and disadvantages of Digital Camera


Advantage Disadvantage
• No processing delay. • Uses a lot of power.
• Easier and quicker to edit. • If the memory card gets
• A backup copy can be made of corrupted, photos can be lost and
any digital images taken. deleted.
• Can be shared easily. • If user has lots of images, they
may need more additional
storage.
• Space so they need an SD card
that can store lots of images.

81
7. 2D Scanners
• 2D scanners are input devices that help in converting 2D documents
as well as images in a digital format.
• 2D scanners can be either handheld or flatbed.
• Some printers come with a built-in flatbed scanner with them.
• To boost the overall functionality of scanners, users can use it with
software like OCR or OMR.
• E.g. OCR converts documents into a computer-readable format. OCR
analyses the patterns of light and dark that make up the letters and
numbers to turn the scanned image into text.

Advantages and disadvantages of 2D Scanner


Advantage Disadvantage
• Flatbed scanners can produce • Use a lot of memory space.
digital document copies that can • Not high in quality compared to
have a higher resolution than a the actual photo.
digital camera. • If quality is not good, then the
• Copies can be edited with scanned one will be worse.
software.
• Scanned document can be
attached to an email.

82
8. 3D Scanners
• An input device like a 2D scanner but can scan 3D models.
• To achieve this type of scanning radio waves, lasers, x-rays or light can
be used.
• It is used majorly for security checking, it can also be found in
biometric devices, etc.
• However, continuous exposure to rays like x-ray or laser can be
harmful.

9. Interactive Whiteboard
• Just like the traditional whiteboard, interactive whiteboards also
widely used for explanations or presentations in schools and offices.
• It consists of a big touch screen (touch-sensitive screen) that allows
the images from the computer system to the interactive board.
• The board also allows to interact with the programs directly by using
the dummy pen or finger.
• The dummy pen or finger can also be used to write or mark on the
board while explaining or during a presentation.

83
10. Touchscreens
• Touchscreens are input devices that are available in three types i.e.
resistive, capacitive and infrared.
• In capacitive touchscreens, an electric current is sent from all corners
of the screen and touch location is detected by the change in electrical
current.
• In resistive touchscreens, there are multiple layers and touch is
detected when the top layer touches the lower layer and electrical
current changes.
• In infrared touchscreen, there are LED beams that form a grid
(invisible) on the screen and the exact location of the touch is detected
when the beam breaks because of the touch.
• It is a screen i.e. touch-sensitive and responds to it as well as it offers
an electronic display to the user.
• Using the touchscreen, the user can interact with the software by
simply touching the screen via a finger or dummy pen.

84
11. Barcode Reader

• It is an input device that can read an image made of white and black
lines.
• These lines represent digits from 0 to 9.
• The barcode reader is able to read the exact digits because the white
and black surfaces reflect the light in a different way.
• With a barcode reader, it is quick and easier to scan the series of
codes as you do not need to type these codes by hand.
• The bar code reader also helps in reducing the error as compared to
manual entry.
• A barcode reader only helps in the identification of the item/product
in order to know details about that specific product, the user must refer
to the database with all the details.
Advantages and disadvantages of Barcode Reader
Advantage Disadvantage
• Efficient and fast method for • If barcode is damaged then it
finding the price of something. will not be able to be scanned
• Keep record of detail. properly.
• Barcode reader won't be able to
scan barcode if the barcode data
isn't stored in computer.

85
12. QR Code Reader
• A QR Code reader is capable of scanning the QR code i.e. a pattern
generated by a computer that can hold a modest amount of
information e.g. website address, contact details, product details, etc.
• A user can access and read the information in the QR code by
scanning it via the QR code reader.
• A QR code reader consists of three parts including illuminator,
decoder, and convertor (sensor).
• The scanner illuminates the QR code with red light and the sensor
then detects the illuminated light which is decoded by the decoder and
information is sent to the computer system.
• Mobile applications are also available on the Play-Store and App-
Store that allows the user to scan the QR code.
• In the case of the mobile, the
information is sent to the mobile
device.

Advantages and disadvantages of


QR Code Reader

Advantage Disadvantage
• Efficient method of storing a • People need a device that can
variety of data such as images. read the QR code.
• Even if some parts of the QR
code is missing, the code can still
be read.

86
Input Devices in Real-Life Scenarios
• At airports, 2D scanners are used to scan the passports.
• The OCR technology is used to produce the digital images of passport
pages.
• These digital images can then be manipulated in various ways.
• For example, the data from the passport’s digital images can be
extracted and copied in the database at the correct fields.
• The text can also be stored in ASCII format, it all depends on how you
want your data to be manipulated.
• At some airports, the image in the passport is also scanned and stored
as a JPEG file.
• The passenger’s photograph (taken from the digital camera) is then
matched with the scanned image for verification using face detection
software.
Barcode Readers in Supermarkets
• The Barcode at supermarkets is a life savior as it not only speeds up the processing of at the cash
counter but it also minimizes the error.

• The customer gathers up the items to purchase in a shopping cart and walks up to the cashier, the
cashier will scan the barcode on items using the barcode reader and he will get all the information
regarding the item from the database on his screen.

• The cashier keeps scanning the items and once he scans all the items he can see the total cost of
the items in the shopping cart.

• The receipt is generated automatically and the cashier can collect the payment in the cash drawer.

• The receipt usually contains information of all the purchased items e.g. their name, quantity, and
cost as well as the total amount given and the amount that the cashier gave back to the customer.

• Each transaction is recorded under the cashier’s account in the database.

• Managers can review the cashier’s transaction by simply connecting to the database.

87
SENSORS
1. Temperature Sensor

 The temperature sensor can detect the temperature changes by


measuring the heat generated by a system/object.
Application
• Control and monitoring of a chemical process.
• Monitoring and control of temperature in a greenhouse.
• Controlling a central heating system.
2. Moisture/Humidity Sensor

 Humidity sensors measure the moisture in the air while moisture


sensors detect the amount of moisture in a material.
Application
• Monitoring moisture level in industries.
• Monitoring and controlling humidity levels in greenhouses

88
3. Light Sensor

 The light sensors can detect the ambiance of the surrounding.


The ambiance refers to the level of brightness/darkness.
Application
• Controlling street lights.
• Automatically turning on vehicle headlights etc.
4. Infrared/Motion Sensor

 The infrared/motion sensors can detect the movement or heat


produced from an object.
Application
• Burglar alarm system.
• Automatic doors etc.

89
5. Pressure Sensor

 These sensors detect the pressure.


There are a number of pressure sensors including resistive
pressure sensors, piezoelectric pressure sensors, and strain gauge
type.
Application
• Weight machine.
• Burglar system etc.
6. Acoustic/Sound Sensor

 It detects the noise levels in the surrounding.


Application
• Burglar system.
• Leakage detection system etc.

90
7. PH Sensor
 It detects the type of material i.e. acidic or alkaline.
Application
• Greenhouse.
• River monitoring for contamination etc.
• 0 to 14
8. Magnetic Field Sensor • 0 7 alkali
• 7 neutral

 It can detect the changes in the magnetic field.


Application
• Mobile phones.
• Car detection in traffic lights etc.
9. Gas sensor

 It can detect and identify different type of gasses.


Application
• Monitoring pollution in gas or air.
• Monitoring the 𝑂2 and 𝐶𝑂2 in a green house.
• Monitoring 𝐶𝑂2 leaks in a power station.

91
Describe how a range of sensors can be used to input data into a
computer system, including light, temperature, magnetic field, gas,
pressure, moisture, humidity, pH and motion.
• Physical data is what is known an analogue. This means that it is
constantly changing and doesn’t have a directive value.
• Analogue data requires some way to interpret. For example, a
mercury thermometer requires you to look at the height of the
mercury.
• Temperature can therefore have an infinite number of values.
• As humans, we can read these values. However, a computer cannot.
The data needs to be converted into a digital format.
• This is done by using an Analogue to Digital Converter (ADC). This
device converts physical analogue values into discrete digital values.
Analogue data
ADC

Digital data

• When computer or microprocessors are used to control devises used


to control devices, it is necessary to use Digital to Analogue Converter
(DAC).
• These are used with an actuator, which is a type of electromechanical
output device used to control something.
• Actuators may require a DAC to receive an electric current rather
than a digital signal.

92
Digital data

ADC

Analogue data

•Digital value is discrete value.


•While analogue is continuous value.
• microprocessor, any of a type of miniature electronic device that
contains the arithmetic, logic, and control circuitry necessary to
perform the functions of a digital computer's central processing unit.

How sensors work in a microprocessor?


Sensors and signals to a microprocessor/computer.

Signals are converted in digital (if required) using an ADC.

The microprocessor/computer checks the data received against store


values.

Monitoring system If the received data is outside a set range… controlling system

A warning message alarm is output. The computer/microprocessor sends


n signals to control actuator.

93
Burglar alarm system
The way how Burglar alarm system works is below:

Street lightning system


The way how Street lightning system works is below:

94
Output Devices chapter 9
Output devices
• Output devices can be described as the devices that are used to show
the information processed by a computer system in a human-readable
form.
• The information shown by output devices can be in text, graphics,
video, audio, etc.

Different Output Devices


1. Printers (Inkjet Printers and Laser Printers)
2. 2D & 3D cutter
3. Headphones & speakers
4. Actuators
5. Flat-panel display screens
6. Projectors

Inkjet Printers

• Inkjet printers are usually used in homes and small offices for printing
less volume of papers.
• It has a moving head that prints characters by spraying droplets of
liquid ink on the ribbon from the cartridge.

95
• They have 4 cartridges for CMYK colors. (Cyan, Magenta, Yellow and
Black).

• These printers produce less noise.

Ink droplets can be produces using these two ways


Thermal bubble
• Tiny resistors will create heat and makes the ink vaporize. The ink
forms a tiny bubble and the bubble will expand.
• Some of the ink will be transferred on to the paper by the printer
head. When bubble collapses, the vacuum is created and fresh ink is
drawn from the printer head.
Piezoelectric
• A crystal is located at the back of the ink reservoir for each nozzle.
The crystal is given an electric charge and it vibrates causing ink to be
ejected onto paper.

Working of ink jet printers


1. Data from document is sent to printer drive.
2. It should be in a format that the printer can understand.
3. A check is made to ensure that the printer is not busy and is on.
4. The data is sent to printer and stored in a temporary memory called
a printer buffer.
5. The printer will check if there is paper. If the paper is jammed or out
of paper, an error message is sent to the computer.

96
6. As paper is sent through printer, the print head moves side to side
spraying CMYK ink.
7. The paper continues going up the printer and allows each line to be
printed. It will continue until the whole page is complete.
8. If there is more data in printer buffer, it will move on to the next data
in print buffer.
9. When is it empty, it will send an interrupt to processor.

Advantages and Disadvantages of ink jet printers


Advantages Disadvantages
Produces less noise. Not suitable for high volume
printing.
Good for printing images. The moveable head is prone to
clogging and damage.
No warm-up time and reasonably Replaceable ink cartridges are
fast. expensive.

97
Laser Printers

• Laser printers are usually used in offices where bulk volume printing is
required.
• Unlike inkjet printers, they use a powder ink cartridge and uses static
electricity for printing.
• The light is used to scan across the printing drum inside the printer in
a back and forth direction.
• This scanning of light forms static electricity that attracts toner
(powdered ink) to the paper.
• A fuser unit is used to bond the ink to the paper.
• Laser printers uses a powder called toner which is provided in a
cartridge.
• They also have 4 cartridges for the CMYK color.
• They use a laser to create static electricity on areas that join up the
image or text being printed.
• Toner is scattered on to the paper and electricity is used to stick the
toner to the paper.
• A fusing element is used after for the toner to bond with the paper.

Working of Laser Printers


1. Data is sent to printer drive.

98
2. Printer driver ensures right format for printer.
3. A check is made to ensure if printer is available to print.
4. Data is sent to printer and stored in printer buffer.
5. It will start when the printing drum is given a positive charge. The
drum rotates and a laser beam is scanned across leaving negatively
charged areas and removing positively charged areas to match text of
page.
6. The drum is coated with a powder called toner and it is positively
charged so it sticks to the negatively charged area.
7. A negatively charged paper is rolled over drum.
8. The toner on drum sticks to paper.
9. Electric charge on paper is removed after the drum rotates to
prevent paper from sticking to drum.
10. The paper goes through a fuser (set of heated rollers) the heat
melts the ink and fixes in in the paper.
11. A discharge lamp removes all electric charge from drum and it is
read to print the next page.

99
Advantages and Disadvantages of Laser Printers
Advantages Disadvantages
Produce high-quality print It takes more space as compared
compared to inkjet printers. to inkjet printers.
It produces a high volume of The toner is more expensive as
prints in very little time. compared to inkjet cartridges.
The cost per page is cheaper as If damaged; it is expensive to
compared to inkjet printers. repair
3D Printers

• 3D printing is also known as additive manufacturing.


• 3D printers are devices that are used to produce three-dimensional
products or prototypes.
• These printers print by laying up material from the ground until the
final product is printed from a 3D computer model.
• The 3D computer model can be created using a 3D scanner as well as
by using CAD modeling software.
• 3D printers are assisting in medical aids, prototyping, human
prosthetics, etc.

100
• The 3D printer uses a material such as polymer, acrylic or plastic. They
will print each layer on top of another which is called addictive
manufacturing.

Working of 3D Printers
1. A design is made using CAD software.
2. The final design is imported to a software that prepares a suitable
format for the 3D printer.
3. The 3D object is set up.
4. Object is built up by layer. The time taken depends on the thickness,
size and material used.
5. Object is removed from printer and then prepared. Some use a
support that needs to be washed with water. Some remove the excess
plastic powder. Some require cutting the unused material. Or they
could be left to dry.

Advantages and Disadvantages


Advantages Disadvantages
It minimizes waste as it uses up a Only a limited choice of material
product that is required for can be used for production.
production only.
It is cost-effective and A large volume of production is
inexpensive compared to not cost-effective compared to
traditional prototype production injection molding.
methods.
It can produce light weight but The layered structure produced
stronger parts. by these printers can delaminate
under some circumstances.

101
• One type of technology 3D printers use is direct printing. This uses
inkjet technology: a print head moves side-to-side like an inkjet printer,
but can also move up and down to build the layers.

• Another type of technology 3D printers use is binder printing. The


print head moves like in direct 3D printing, but two substances are
sprayed for each layer: dry powder and binder to form the object.

• Other technologies make use of UV light to harden liquid polymers,


which increases the diversity of products that can be produced.

Cutters
2D Cutters

• It is an output device that cut holes or shapes on a 2D flat surface.

• It can be a paper cutter or an industrial metal cutter.

• The cutter uses a laser to cut through different materials and


different thickness surfaces without the need to change the machine.

• It provides precision cutting cost-effectively.

102
3D Cutters

• 3D laser cutters are like 2D laser cutters but they can cut at many
different angles.

• There are different types of 3D cutters available and some do not use
a laser to cut through the object.

• These cutters have the ability to cut beneath the object's surface
without scratching or damaging.

• The surface beneath cutting is typically done in glass or crystals.

• A laser cutter can cut materials such as glass, polymer, metal, crystal
and wood.
• A 2D laser cutter cuts in the x-y direction, while a 3D laser cutter cuts
in the x-y-z direction.
• The laser cutters are controlled by computers, which means that
complex and cool designs can easily be made.

103
Speakers and Headphones

• Speakers and headphones are both used for producing sound as an


output.
• Speakers produce the sound that can fill the room whereas,
headphone keeps the sound to one wearing it.
• These output devices produce sound by converting the digital signals
into analogous sound waves.
• These sound waves are audible to human ears.
• These output devices can be used to hear music as well as to
communicate and listen to other people.
• A device that converts electrical impulses to sound.
• Sound is produced from a computer by transmitting digital values
through a DAC and then through an amplifier and finally to a speaker,
where it is an output.
Computer Digital data DAC Analogue data

Speaker Amplified data Amplifier

104
• The rate that the DAC can convert the digital data into analogue
voltages is known as the sampling rate.
If the DAC is 16-bit, it can accept 216 (65,536) numbers (-32,768 to
32,767). The speed that these values can be converted is the sampling
rate.
• The typical sampling rate is 44,100 Hz (samples per second). This
means that the DAC is able to convert 44, 100 values every second.
• For example, a CD is being produced to hold a number of music files.
• Each music file will be sampled 44,100 times per second, each sample
being 16 bits.
• We must also take into consideration the music being stereophonic.
• Taking the above into account, we can calculate how many bits per
second can be sampled to the CD.
Stereophonic: reproducer in which two microphones feed two or more
loudspeakers to give a three-dimensional effect to the sound.

(44,100) (16) (2) = 1,411,200 bits per second (multiply 2 if it is a music file music file)
8 bits = 1 byte
1,411,200
= 176,400 bytes per second
8

Actuators

105
• Actuators are used in robotics and control systems.
• These are output devices often control the movement in the real
world by taking a signal from the microprocessor.
• For example, automatic mall doors.
• An actuator (such as a motor, relay or solenoid) is used in a
controlling application.
• When energized, an actuator can operate or control a system (for
example, a solenoid could be used to operate a plunger or control a
fuel injection system).
• A DAC is sometimes required to control an actuator. A computer is
connected with the actuator and data sent to it will go through the DAC
when being transmitted to the actuator
Fuel injection: to deliver fuel into the engine cylinders, while precisely controlling
the injection timing, fuel atomization, and other parameters.

Displays
• Displays are electronic device to output information using a screen or
projector.
• It can be in the form of text, images or videos.
• An external device such as one with a desktop PC can be called a
monitor or virtual display unit (VDU).
❑ Image is built up of pixels (illuminated dots to form an image). The
quality of image depends on the resolution of display.
• Normal smartphones will have an 800 x 480 resolution.
• A normal projector will have a 1024 x 768 resolution.
• Standard-definition TV will have a 1280 x 720 resolution.

106
• High-definition TV will have a 1920 x 1080 resolution.
• 4k TV will have a 3840 x 2160 resolution.
•Display that has large number of pixels will have a high-resolution
display. It outputs a clear image with a high level of detail.
•Displays will either use monochrome (background and foreground
color - black and white) or color images (uses primary colors, RGB).
• Displays also have a color depth to show how bright or pale a color is.

Flat-Panel Display Screens

• These are the most common form of output devices.


LCD Screens:
• Flat panel displays: Flat panel displays are thinner and provide higher-
resolution images and uses less energy. However, it is very expensive
and can be easily damaged if dropped and can suffer from dead pixels.
• In LCD screens, the display is created by combining green, blue and
red light filters available in each pixel.
• In a single LCD screen, there are millions of pixels (tiny blocks)
available.
• Showing display is possible in LCDs because each pixel has liquid
crystals that can be manipulated to allow fluorescent tube backlight in
controlled proportion via the RGB filters on the screen front.

107
TFT/LCD/Plasma

• (Liquid crystal display monitors) or (thin-film transistors) are made up


of diodes. The screens provide more brighter and vivid colors. LCD
originally used cold cathode fluorescent lamps.
• Now, they have been changed to LED’s.

LED Screens

• These are similar to LCD screens however, the light source in both is
different.
• In LED screens, small LED bulbs are responsible for providing the light.
• In some screens, the entire display unit back is covered with these
bulbs and in other models, only the edges have these bulbs.
• The screens with only edges bulbs are thinner.

108
• LED screens are power efficient in comparison to LCD screens. While a
standard LCD monitor uses fluorescent backlights, an LED monitor uses
light-emitting diodes for backlights.
While a standard LCD monitor uses fluorescent backlights, an LED monitor uses light-emitting diodes for
backlights.

OLED - (Organic Light-Emitting Diode)

• OLED panels are made from organic materials that emit light when
electricity is applied through them which means they do not need a
backlight. When it is switched on, the cathode will receive electrons
and anode loses them.
• Electrons and positively charged particles meet, they release light.
• Advantages are:
• That they are thinner and more flexible than crystalline layers.
• They are brighter than LEDs and does not require backlight or filters.
• It has great picture quality and fast response rates.
• However, water can easily damage OLEDs and the manufacturing
process is complicated which makes them very expensive.

109
QLED - (Quantum Dot Light Emitting Diode

• QLED uses a LCD that uses quantum dots (2-10 nanometers in


diameter) to emit light. They add another extra layer of quantum dots
to change the colors.
• Quantum dots (QDs) are man-made Nano scale crystals that that can transport electrons.
When UV light hits these semiconducting nanoparticles, they can emit light of various colors.

• The advantages are that it can emit brighter light and can deliver wide
ranges of colors, it also lights from individual pixels.
• They are more cost-effective and are much safer.
• However,
• They also have a lower resolution due to afterglow and light leakage.
• It also can't project true black color and there is a poor viewing angle.
Light leakage: under an oblique viewing angle results in color shifts and
a reduction of contrast ratio.

Afterglow: a glow remaining where a light has disappeared.

110
Micro LED - (Microscopic Light Emitting Diodes)

• Technology which uses inorganic material.


• It has arrays of microscopic LEDs forming pixel elements. Mostly
aimed at smartphones or smart watches. Constructed from light
emitting diodes measuring less than 100µm.
They are thinner than OLED and QLED, they have a very high response
time and a longer lifespan.
• They produce very high contrast ratios and deep black colors and
have energy efficiency.
• However, they are 3-4 more times more expensive than OLED panels
and there may be accuracy issues in placing micro LED components into
array.

Projectors

• Projectors are output devices that show the display over the wall or
large screen from a computer system.
• Projectors are best used during presentations or class lectures.
• Prices vary for different projectors; small projectors are reasonable
but projectors capable of displaying movies in cinemas are expensive.

111
Digital Projectors

• Display device connected to a computer used to project an image or


video on to a flat area e.g. the wall or whiteboard.
• They are used on a large scale for a large audience.
• The further away from wall, the larger the image. But the dimmer the
image.
• There are two types:
LCD and DLP Projectors

LCD Projectors

• In LCD projectors, a high-density light beam passes through the LCD


to the screen or wall.

112
• In a projector, there is a LED/ bulb from which a powerful white light
is generated.
• A group of chromatic coated mirrors is used to reflect this white light
at different wavelengths.
• The reflected light has wavelengths equal to RGB.
• These three different light wavelengths, show the image to be
displayed in greyscale and with the help of the colored light that passes
through the LCD, a colored version emerges from the greyscale images.
• Using a special prism, these images are then combined and the
projector lens displays the image on the wall/screen.
1. A beam of white light is generated from a bulb or LED in the
projector.

2. The beam is sent to a group of chromatic-coated mirrors, which


reflect the light back at different wavelengths corresponding to red,
green and blue light components.

4. These are then combined using a type of prism to produce an image


consisting of millions of colors. This image is then passed through the
projector lens onto a wall/screen.

1. These colored light components pass through three LCD screens


and a red, green and blue version of the grey image emerges.

113
DLPs Projectors

• DLPs use millions of micro mirrors on a chip. The number of micro


mirrors and the way they are arranged determines the resolution of the
image projected.
• When the micro mirrors are tilted towards the light source, they are
'on'. When they are tilted away from the light source, they are 'off'.
• The micro mirrors can switch on or off thousands of times a second to
create various shades of grey. The typical number of grey shades which
can be produced is 1024.
• For example, if the mirror turns on more times that it turns off, a
lighter shade of grey will be produced.
• Unlike an LCD projector, it uses a fast-spinning color wheel filter.
• The filter is responsible for splitting the lamp light into RGB light.
• A bank (chip) made up of thousands of microscopic mirrors (pixels) is
used to project the image.
• The color wheel filter and mirrors are synchronized to turn away or
towards the light as required.
• The image is then magnified and projected out of the sense on the
screen/wall. (https://www.youtube.com/watch?v=CI0cwk25CAs)

114
Network Hardware chapter 10
Network Interface Cards (NIC)

Understand that a computer needs a network interface card (NIC) to


access a network.
• A network interface card (NIC) is a hardware component which
enables a computer to connect to a network (e.g., home network or
Internet).
• It is a circuit board installed in a computer that provides a dedicated
network connection for the computer.
• It is also called a network interface controller, network adapter, LAN
adapter or Ethernet card.

Media Access Control (MAC)


Understand what is meant by and the purpose of a media access
control (MAC) address, including its structure.
• Just like each house has its own postal address, every device
connected on a network has a Media Access Control (MAC) address
that uniquely identifies it. The MAC address is linked to the Network
Interface Controller (NIC) in a device.

115
• The MAC address is a 12 digit hexadecimal number that is most often
displayed with a colon or hyphen separating every two digits, making it
easier to read.
(NN – NN – NN – DD – DD – DD)
NN – NN – NN – DD – DD – DD

Manufacturer’s Code device serial number


• Where the first six hex digits identify the device as made by, for
example, Apple and the second set of six hex digits are the serial
number of the device itself (this is unique).
• If the NIC card is replaced, the MAC address will also change.

Internet protocol (IP) address


• An Internet Protocol (IP) address is the unique number that gets
assigned to your connected device. Every mobile phone, laptop, cable
box, tablet, server along with thousands of other types of devices that
are connected to a computer network or the internet has one.
• IP stands for "Internet Protocol," which is the set of rules governing
the format of data sent via the internet or local network.
• The internet needs a way to differentiate between different
computers, routers, and websites. IP addresses provide a way of doing
so and form an essential part of how the internet works.

116
How Internet Protocol (IP) address works:
• Your computer, phone or tablet indirectly connects to the internet by
connecting at first to a network connected to the internet, which then
grants your device access to the internet.
• When you are at home, that network will usually be your Internet
Service Provider (ISP). At work or school, it will be your company
network.
• Your IP address is assigned to your device by your internet serves
provider (ISP).
(An IPv6 128-bit address take the form of eight groups of hex digits; for example:
A8FB:7A88:FFF0:0FFF:3D21:2085:66FB:F0FA)

• Your internet activity goes through the ISP, and they route it back to
you, using your IP address. Since they are giving you access to the
internet, it is their role to assign an IP address to your device.
• However, your IP address can change. For example, turning your
modem or router on or off can change it. Or you can contact your ISP,
and they can change it for you.
• When you are out and about - for example, traveling - and you take
your device with you, your home IP address does not come with you.
This is because you will be using another network (Wi-Fi at a hotel,
airport, or coffee shop, etc.) to access the internet and will be using a
different (and temporary) IP address, assigned to you by the ISP of the
hotel, airport or coffee shop.

117
Difference between MAC and IP Addresses
MAC addresses IP addresses
Identifies the physical address of Identifies the global address on
a device on the network. the internet.
unique for device on the network may not necessarily be unique
Assigned by the manufacturer of Dynamic IP addresses are
the device and is part of the NIC. assigned by ISP using DHCP each
time the device connects to the
internet.
They can be universal or local. Dynamic IP addresses change
every time a device connects to
the internet; static IP addresses
don't change.
It use 48 bits. Use either 32 bits (IPv4) or 128
bits (IPv6).
Can be UAA or LAA. can be static or dynamic

Static vs. Dynamic IP Addresses


STATIC IP Address: As the name suggests, a static IP address does not
change. Businesses offering dedicated internet services such as web
hosting prefer static IPs for this reason. These are assigned manually by
internet service providers (ISPs).
Pros at a glance Cons at a glance
• Ideal for hosting computer • Difficult to set up and manage.
servers. • More vulnerable to hacking.
• Facilitates faster data exchange. • Generally more expensive.
• Supports remote desktop
access.

118
Static vs. Dynamic IP Addresses
Dynamic IP Address: This is temporary and may change when you
reboot your system or the router. ISPs assign dynamic IP addresses as
needed via a dynamic host configuration protocol server (DHCP server).
Most devices have dynamic addresses, as they're secure. When a
dynamic address is not in use, an ISP assigns it to a different device.
Pros at a glance Cons at a glance
• Automatically configured; • Makes it nearly impossible to
requires no additional setup. set up remote access.
• Less prone to hacking. • Can cause downtime when
• Cost-effective. disconnected.
• Affects performance of
geo-location services.
Routers

Describe the role of a router in a network.


• A router sends data to a specific destination on a network.
• A router can connect a local network to the internet.
• Can assigns a local IP address to each device on the network.
• Creates a firewall to prevent security breaches.
• Manages the traffic on your network.
• Handles any Parental Controls on a Home local area network (LAN)
network.

119
The router is a device that is designed to receive, analyze, and
forward data packets between computer networks.
• By enabling data packets to be routed between different networks,
for example, to join a local area network (LAN) to a wide area network
(WAN). The router takes data transmitted in one format from a
network (which is using a particular protocol) and converts the data to
a protocol and format understood by another network, thereby
allowing them to communicate.
• Routers inspect the data package sent to it from any computer on any
of the networks connected to it.
• Every computer on the same network has the same part of an
internet protocol (IP) address, the router is able to send the data packet
to the appropriate switch/node, and the data will then be delivered to
the correct device using the MAC destination address.
• If the MAC address doesn't match any device connected to the
switch, it passes on to another switch on the same network until the
appropriate device is found.
• Routers can be wired or wireless devices.

120
Software chapter 11
System software and application software
• Installed on your computer,
depending on whether you have
chosen a MAC or PC, will be an
OPERATING SYSTEM, maybe iOS
or WINDOWS.
• The Operating System also
includes utility programs and
hardware drivers.
• On top of the Operating
System, APPLICATION SOFTWARE
can be installed such as
Spreadsheet and Word
Processing applications.

Software Types SOFTWARE

SYSTEM SOFTWARE APPLICATION SOFTWARE

Operating
system
Spread Data Games
Utility sheet base s/ware
programs

Device Word Internet


drivers proces browser
sor
121
General features of system software
• Set of programs to control and manage the operation of computer
hardware.
• Provides a platform on which other software can run.
• Required to allow hardware and software to run without problems.
• Provides a human computer interface (HCI).
• Controls the allocation and usage of hardware resources.

General features of application software


• Used to perform various applications (apps) on a computer.
• Allows a user to perform specific tasks using the computer's
resources.
• May be a single program (for example, Notepad) or a suite of
programs (for example, Microsoft Office).
• User can execute the software as and when they require.
Word Processor
• Word processing software is used to manipulate a text document,
such as an essay or a report. Text is entered using a keyboard and the
software provides tools for copying, deleting and various types of
formatting. Some of the functions of word processing software include:
 Creating, editing, saving and manipulating text.
 Copy and paste functions.
 Spell checkers and thesaurus.
 Import photos/images into a structured page format.
 Translation into a foreign language.

122
Spreadsheet
• Spreadsheet software is used to organize and manipulate numerical
data (in the form of integer, real, date, and so on). Numbers are
organized on a grid of lettered columns and numbered rows. The grid
itself is made up of cells, and each cell is identified using a unique
combination of columns and rows, for example, B6. Some of the
functions of spreadsheets include:
 Use of formulas to carry out calculations ability to produce
graphs.
 Ability to produce graphs.
 Ability to do modelling and "what if' calculations.
Database
• Database software is used to organize, manipulate and analyze data.
A typical database is made up of one or more tables. Tables consist of
rows and columns. Each row is called a 'record' and each column is
called a 'field.' This provides the basic structure for the organization of
the data within the database. Some of the functions include:
 Ability to carry out queries on database data and produce a
report.
 Add, delete and modify data in a table.

123
Examples of application software
Apps
Apps is short for applications-a type of
software.
They normally refer to software which runs
on mobile phones or tablets. They are
normally downloaded from an "App Store"
and range from games to sophisticated
software such as phone banking.
• Common examples of apps include:
 Video and music streaming.
 GPS (global positioning systems-help you find your Way to a chosen
location)
 Camera facility (taking photos and storing/manipulating the images
taken).

Video editing software


• Video editing software is the ability to manipulate
videos to produce o new video. It enables the addition
of titles, color correction an altering/adding sound to the
original video.
• Essentially it includes:
 Rearranging, adding and/or removing sections of
video clips and/or audio clips
 Applying color correction, filters and other video
enhancements
 Creating transitions between clips in the video
footage.

124
Control & measuring software
• Control and measuring software is designed to allow a computer or
microprocessor to interface with sensors so that it is possible to:
 Measure physical quantities in the real world (such as
temperatures).
 To control applications (such as a chemical process) by comparing
sensor data with stored data and sending out signals to alter
process parameters (e.g. open a valve to add acid and change the
PH).

Examples of system software Operating Systems (OS):


• The operating system (OS) is essentially software running in the
background of a computer system. It manages many of the basic
functions. Without the OS, most computers would be very user-
unfriendly and the majority of users would find it almost impossible to
work with computers on a day-to-day basis.
• For example, operating systems allow:
 Input/output operations.
 Users to communicate with the computer.
 Error handling to take place.
 The loading and running of programs to occur.
 Managing of security (e.g. user accounts, log on passwords).

Utilities
• Utility programs are software that are designed to carry out specific
tasks on a computer. Essentially, they are programs that help to
manage, maintain and control computer resources.

125
• Examples include:
 Anti-virus (virus checkers).
 Anti-spyware backup of files.
 Disk repair and analysis.
 File management and compression.
 Security.
 Screensavers.
 Disk defragmentation software.

Virus checkers (anti-virus software)


• Antivirus is a kind of software used to prevent, scan, detect and
delete viruses from a computer. Once installed, most antivirus software
runs automatically in the background to provide real-time protection
against virus attacks.
• Comprehensive virus protection programs help protect your files and
hardware from malware such as worms, Trojan horses and spyware,
and may also offer additional protection such as customizable firewalls
and website blocking.
• They are able to check software or files before they are run or loaded
on a computer. They compares a possible virus against a database of
known viruses.

126
Back-up software
• While it is sensible to take manual back-ups using, for example, a
memory stick or portable HDD, it is also good practice to use the
operating system back-up utility.
This utility will:
 Allow a schedule for backing up files to be made.
 Only carry out a back-up procedure if there have
been any changes made to a file.
For total security there should be three versions of a file:
1. The current (working) version stored on the internal
HDD or SSD.
2. A locally backed up copy of the file (stored on a portable SSD).
3. A remote back-up version stored well away from the computer (for
example, us cloud storage).

Operating Systems

• In order for computer systems to function correctly and allow users to


communicate with iOS them, software known as an operating system
needs to be installed.
• An operating system provides both the environment in which
applications can be run and a useable interface between humans and
computer.

127
• An operating system make using computer hardware much easier.
Examples of operating systems include: Microsoft Windows, Apple Mac
OS, Google Android and Apple IOS.

What is the purpose of an Operating Systems?


Here is a summary of
some of the functions
in a typical operating
system.
Operating Systems

Hardware peripheral management (including drivers)

Memory management

Interrupt handling routines

Security (manages log on, passwords)

Human computer interface (HCI)

Multitasking

Platform for running of application software

Management of user accounts

Managing files

128
Functions of operating system
1. Memory management
• Manages the primary storage (RAM) and allows data to be moved
between RAM and HDD/SSD during the execution of programs.
• Keeps track of all the memory locations.
• Carries out memory protection to ensure that two competing
applications cannot use the same memory locations at the same time. If
this wasn't done the following might happen:
 Data would probably be lost.
 Applications could produce incorrect results (based on the wrong
data being in memory locations).
 Potential security issues (if data is placed in the wrong location, it
might make it accessible to other software, which would be a
major security issue).
 In extreme cases, the computer could crash.
2. Security management
• Security management is another job of the operating system; its
function is to ensure the integrity, confidentiality and availability of
data.
• Tasks include:
 Carrying out updates as and when they become available
 Ensuring that anti-virus software is always up to date.
 Communicating with a firewall to check all traffic to and from the
computer.
 Using 'privileges' to prevent users entering 'private areas' on a
computer that permits multi-user activity, his helps to ensure the
privacy of data.
 Maintaining access rights for all users.

129
 Offering the ability for the recovery of data when it has been lost
or corrupted.
 Helping to prevent illegal intrusion into the computer system.
3. Hardware peripheral management
• This involves the management of all input and output peripheral
devices.
• Tasks include:
 Communicates with all input and output devices using device
drivers ensures each hardware resource has a priority so that
they can be used and released as required.
 Manages input/output devices by controlling queues and
buffers; for example, the role of the printer management when
printing out a document:
 First the printer driver is located and loaded into memory.
 The data is then sent to a printer buffer ready for printing.
 If the printer is busy then the data is sent to a printer queue
before it can be sent to the printer buffer.
 It receives and handles error messages and interrupts from the
printer.

4. File management
• File management tasks include:
 File naming conventions which can be used i.e. filename.docx
(where the extension can be .bat, .htm, .dbf, .txt, .xls, etc.).
 Performing specific tasks, such as: create, open, close, delete,
rename, copy, and move files.
 Maintain the directory structures.

130
 ensuring access control mechanisms are maintained (for
example, access rights to files, password protection, or making
files available for editing or locking them).
 Ensuring memory allocation for a file by reading it from the
HDD/SSD and loading it into memory.
5. Management of user accounts
• Computers allow more than one user to log onto the system. It is
therefore important that users' data is stored in separate parts of the
memory for security reasons.
• Each person logging onto the computer will be given a user account
protected by a user name and password. The operating system is given
the task of managing these different user accounts.
• This allows each user to:
 Customize their screen layout and other settings use.
 Separate folders and files and to manage these themselves.
• Usually an administrator oversees the management of these user
accounts. The administrator can create accounts, delete user accounts
and restrict user account activity.

Running of applications
• When a computer starts up, a part of the operating system is loaded
into RAM- this is known as booting up the computer.
• The start-up of the computer's motherboard is handled by the basic
input or output system (BIOS).

131
Firmware
• Firmware is software that's embedded in a piece of hardware. You
can think of it simply as "software for hardware." However, software is
different from firmware, so the two are not interchangeable terms.
• Devices that you might think of as strictly hardware such as an optical
drive, network card, TV remote, router, media player, camera, or
scanner all have software that's programmed into a special memory
contained in the hardware itself.

Interrupts
• An interrupt is a signal from a device attached to a computer or from
a program within the computer that requires the operating system to
stop and figure out what to do next.
• Interrupts can be caused by:
 An input/output process (e.g. a disk drive or printer requiring
more data).
 A hardware fault (for example, a paper jam in the printer).
 User interaction, for example, the user presses <CTRL> <ALT>
<BREAK>, which causes the system to be interrupted.
 software errors that cause a problem (for example, an .exe file
that cannot be found to initiate the execution of a program, two
processes trying to access the same memory location, or an
attempt to divide by zero).
• Interrupts allow computers to carry out many tasks or to have several
programs open at the same time. An example would be downloading a
file from the internet at the same time as listening to some music in
iTunes.

132
• Interrupts allow these two functions to co-exist and the user has the
impression that both functions are being carried out simultaneously.
• In reality, data is being passed in and out of memory very rapidly
allowing both functions to be serviced. This can all be achieved by using
an area in memory known as a buffer.

Buffers
• A buffer is a memory area that stores data temporarily.
• For example, buffers are used when downloading a movie from the
internet to compensate for the difference between download speeds
and the data requirements of the receiving device.
• The data transmission rate of the movie file from the web server to
then buffer must be greater than the rate at which data is transmitted
from buffer to media player.
• Without buffers, the movie would frequently 'freeze'.

133
Types of programming language, translators and
integrated development environments (IDES)
• People use many different languages to communicate with each
other. In order for two people to understand each other they need to
speak the same language or another person, an interpreter, is needed
to translate from one language to the other language.
• Programmers use many different programming languages to
communicate with computers.
• However, computers only 'understand' their own language, this is
called machine code. A program needs to be translated into machine
code before it can be 'understood' by a computer.
• Programs are our way of telling a computer what to do, how to do it
and when to do it.
• This enables a single computer to perform many different types of
task.
• A computer can be used to stream videos, write reports, provide
weather forecasts and many, many other jobs.

134
Low-level languages Assembly languages: Fewer
programmers write programs in an
Low-level languages can assembly language. Those
refer to Machine Code or programmers who do, do so for the
Assembly Language. following reasons:
These are the simple  To make use of special hardware.
instructions that a  To make use of special machine-
computer understands. dependent instructions.
Assembly language that
 To write code that doesn't take up
needs to be translated
much space in primary memory.
into machine code.
 To write code that performs a task
very quickly.

Machine Code: Programmers do not usually write in machine code


as it is difficult to understand, and it can be complicated to manage
data manipulation and storage.

High Level Languages


• High-level languages enable a programmer to focus on the problem
to be solved and require no knowledge of the hardware and instruction
set of the computer that will use the program.
• Many high-level programming languages are portable and can be
used on different types of computer.
• High-level languages are designed with programmers in mind;
programming statements are easier to understand than those written
in a low-level language.
• This means that programs written in a high-level language are easier
to:

135
 Read and understand as the language used is closer to English.
 Write in a shorter time.
 Debug at the development stage.
 Maintain once in use.

Differences between high-level and low-level languages


Language Advantages Disadvantages
• Independent of the type of • Programs can be larger.
computer being used. • Programs can take longer
• Easier to read, write and to execute.
High-level understand programs. • Programs may not be
• Programs are easier and able to make use of special
quicker to debug. hardware.
• Easier to maintain
programs in use.
• Can make use of special • It takes a longer time to
hardware. write and debug programs.
• Includes special machine- • Programs feel more
dependent instructions. difficult to understand.
Low-level • Can write code that doesn't
take up much space in
primary memory.
• Can write code that
performs a task very quickly

136
Compilers
• A compiler is an example of a translator that takes a High-Level
Programming Language (e.g., C++) and translates it into Machine
Language or Assembly Language which the computer can understand.
• It converts the High-Level Language into Machine Code all in one go
so that it can be directly used by a computer to perform a required
task. Once converted, the code can be run unassisted at any time. This
process is called compilation.
• If errors are detected, then an error report is produced instead of a
compiled program.

Interpreters
• An interpreter is a computer program that reads a statement from a
program written in a high-level language one instruction at a time. It is
similar to a human translator translating what a person says into
another language, sentence by sentence, as they speak. The resulting
code is then executed immediately. The process is called interpretation.
• If there is an error in the statement then execution ceases and an
error message is output, sometimes with a suggested correction.
• The program needs to be interpreted again each time it is run.

Assemblers
• Assemblers are a third type of translator. The purpose of an
assembler is to translate assembly language into machine code.
• Whereas compilers and interpreters generate many machine code
instructions for each high level instruction, assemblers create one
machine code instruction for each assembly instruction.

137
Summary of Translation types
Compiler Interpreter Assembler
Translates a high-level Executes a high-level Translates a low level
language program language program assembly language
into machine code. one statement at a program into machine
time. code.
An executable file of No executable file of An executable file of
machine code is machine code is machine code is
produced. produced. produced.
One high-level One high-level One low-level
language statement language program language statement
can be translated into statement may usually translated into
several machine code require several one more code
instructions. machine code instruction.
instructions to be
executed.
Compiled programs Interpreted programs Assembled programs
are run without the cannot be run are used without the
compiler. without the assembler.
interpreter.
A compiled program An interpreter is An assembled
is usually distributed often used when a program is usually
for general use. program is being distributed for
developed. general use.

138
The advantages and disadvantages of compilers and
interpreters
Compiler Interpreter
• A compiled program can • Easier and quicker to
be stored ready for use. debug test programs
• A compiled program can during development.
be executed without the • Easier to edit
compiler. programs during
Advantages • A compiled program development.
takes up less space in
memory when it is
executed.
• A compiled program is
executed in a shorter time.
• It takes a longer time to • Programs cannot be
Disadvantages write, test and debug run with the interpreter.
programs during • Programs can take
development. longer execute.
Integrated Development Environment (IDE)
• An Integrated development environments (IDE) is used by
programmers to aid the writing and development of code. They are
designed to bring together all programming tasks in one application;
one of the main benefits of an IDE is that they offer a central interface
with all the tools a developer needs.
• There are many different IDEs available; some just support one
programming language, others can be used for several different
programming languages. You may be using PyCharm (for Python),
Visual Studio (for Visual Basic) or Blue (for Java) as your IDE.
• IDES usually have these features:

139
 Code editors.
 A translator.
 A debugger.
 Error diagnostics.
 Auto-completion.
 Auto-correction.
 An auto-documenter and pretty-printing.

Code editors are designed for Translators transform source


writing and editing source code that is written in a human
code, these editors are readable/writable language in
distinguished from text editors a form that computers can
because work to either simplify execute.
or enhance the process of
writing and editing of code for Debuggers are used during
developers. testing and can help
developers debug their
application programs.

140
The Internet & it’s uses chapter 12
The differences between the internet and the World
Wide Web
• The word internet is short for Interconnected Network, since it is
basically a worldwide collection of interconnected networks.
• The internet is actually a concept rather than something tangible
(that is, something we can touch). It relies on a physical infrastructure
that allows networks and individual devices to connect to other
networks and devices.
• On the other hand, the World Wide Web (WWW) is only a part of the
internet that users can access using web browser software. The World
Wide Web consists of a massive collection of web pages, and is based
on the hypertext transfer protocol.
• The World Wide Web is a way of accessing this information using the
internet; so the internet and the World Wide Web are actually quite
different.
The INTERNET The WORLD WIDE WEB (WWW)
Internet is a means of connecting World Wide Web which is a
a computer to any other collection of information which is
computer anywhere in the world. accessed via the Internet.
Internet can be viewed as a big Web can be viewed as collection
book-store. of books on that store.
Internet is infrastructure. WWW is service on top of that
infrastructure.
Users can send and receive It is a collection of multimedia
emails. web pages and other information
on websites.

141
Internet is primarily hardware- WWW is more software-oriented
based. as compared to the Internet.
Internet uses IP address. WWW uses HTTP.
Web Browsers
• Web browsers are software that allow users to access and display
web pages on their device screens.
• Browsers interpret hypertext markup language (HTML) sent from
websites and produce the results on the user's device.
• The features in browser are:
 They have a home page.
 They keep a history of websites visited by the user (user history).
 They have the ability to allow the user to navigate forwards and
backwards through websites/web pages already opened.
 They can store a user's favorite websites/web pages (referred to
as bookmarks).
 Many web pages can be open at the same time by using multiple
tabs.
 They make use of hyperlinks that allow navigation between
websites and web pages.
 They make use of cookies.
 They use an address bar.
 Data is stored as a cache.
 Make use of JavaScript.
Uniform resource locators (URLs)
• The protocol is usually either Hyper Text Transfer Protocol (http) or
Hyper Text Transfer Protocol Secure (https).
• The website address is:
 Domain host (www).
 Domain name (website name).

142
 Domain type (.com, .org, .net, .gov, for example).
 And sometimes country code (.pk, .de, .cy, for example).
• The path is the web page, but is often omitted and it then becomes
the root directory of the website.
• The file name is the item on the web page.
The different protocols
• HTTP (Hypertext Transfer Protocol) is a communication protocol. It
defines how communication takes place between a browser and the
web server.
• HTTPS is HTTP with encryption.

• The difference between the two protocols is that HTTPS uses TLS (SSL)
to encrypt normal HTTP requests and responses.
• As a result, HTTPS is far more secure than HTTP.
• A website that uses HTTP has HTTP:// in its URL, while a website that
uses HTTPS has HTTPS://.
Retrieval and location of web pages
• The use of domain names is (No Title) a problem for machines since
they communicate using IP addresses.
• This is because the Internet is based on TCP/IP protocol, which uses IP
addresses for identifying devices.

143
• Hence, domain names given by humans must be changed to their
specific corresponding IP addresses.
• For this purpose, there are name servers.
• The entire system is called Domain Name System (DNS).

• The Domain Name Server (DNS) is a system for finding IP addresses


for a domain name given in a URL.
• It is essentially the 'phonebook' of the Internet.
• URLS and domain name servers eliminate the need for a user to
memories IP addresses.
Cookies
• Cookies are small files or code stored on a user's computer.
• They are used to identify your computer as you browse the internet.
Cookies are used to identify who you are and improve your web
browsing experience.
• Data stored in a cookie is created by the server upon your connection.
This data is labeled with an ID unique to you and your computer.
• When the cookie is exchanged between your computer and the
network server, the server reads the ID and knows what information to
specifically serve to you.

144
• Each cookie is effectively a small look-up table containing pairs of
(key, data) values, for example, (surname, Jones) (music, rock).
• Cookies track data about users, such as IP addresses and browsing
activity.
• A website cookie does not collect personal data from the online user's
hard drive. For example, it does not collect your banking details,
contact addresses, and photographs. Cookies simply carry the data we
create by browsing.

Cookies contain records


of our interactions.

• Collecting data can also be used to customize the web page for each
individual user.
• If a user buys a book online, the cookies remember the type of book
chosen by the user and the web page will then show a message such as
"Customers who bought Chamber of Secrets also bought The Unofficial
Harry Potter Spell Book".

Two types of cookie


 Session cookie
• These are also called Non-Persistent Cookies or Temporary Cookies,
are stored in memory and never written to the disk. Session cookies
remain active as long as the browser remains active - once the browser
is closed, the cookies vanish.
 Persistent cookie
• These cookies remember a user's log-in details (so that they can
authenticate the user's browser). They are stored on the hard drive of a
user's computer until the expiry date is reached or the user deletes it.

145
Session cookies:
• This type of cookie is stored in temporary memory on the computer.
It doesn't actually collect any information from the user's computer and
doesn't personally identify a user.
• Hence, session cookies cease to exist on a user's computer once the
browser is closed or the website session is terminated.
• Session cookies are used, for example, when making online
purchases. It stores the products the user has added to their cart. So
when the user opens a new page, the products remain in the cart.
Without session cookies, a user wouldn't be able to add multiple items
to their cart.

Persistent cookies:
• Persistent cookies are stored on a user's device to help remember
information, settings, preferences, or sign-on credentials that a user
has previously saved. This helps create a convenient and faster website
experience.
• These cookies have an expiration date issued to it by the webserver.
• Persistent cookies track visitors as they move around the website to
figure out what people like about the website to help improve the user
experience.
• The most popular persistent cookie is a Google Analytics cookie.

146
• The first time a user visits a website:
The browser visits Web server (www)
webpage website replies and sends
for first time cookie back to the
user's browser

Persistent Cookie Session Cookie

Summary of the uses of cookies


• Allow the website to remember users' passwords, email addresses
and invoice details, so they won't have to insert all of this information
every time they visit or every time they purchase something from that
website.
• Serve as a memory, enabling the website to recognize users every
time they visit.
• It save users' items in a virtual shopping basket/cart track internet
habits and users' website histories or favorites/bookmarks
• Target users with advertising that matches their previous buying or
surfing habits.

147
The history and evolution of money

Digital Currency
• Digital currency exists purely in a digital format, electronically on a
computer.
• It has no physical form unlike conventional fiat currency (for example,
$, £, €, and ¥).
• (Note: Fiat is a Latin word meaning 'let it be done'; since conventional
currency is backed by governments and banks rather than being linked
to gold or silver reserves, it is referred to as fiat currency.)
• Digital currency is an accepted form of payment to pay for goods or
services. As with cash or credit/debit cards, digital currency can be
transferred between various accounts when carrying out transactions.
(This is still controlled by a central bank).
• It has made it possible to bank online (for example, using PayPal) or
via a smartphone app (for example, Apple Pay).

148
• This is all possible because money only exists as data on a computer
system, but it can be transferred into physical cash if we need it.
• Digital currency relies on a central banking system. For example,
suppose Nick wishes to send Irina some money; Nick uses bank 'X' and
Irina uses bank 'Y’.

• The problem with centralization is maintaining confidentiality and


security; these have always been issues with digital currency systems.
Now there is an alternative!
• One example of digital currency, known as crypto currency, has
essentially overcome these issues by introducing decentralization:

Crypto currency
• Crypto currency uses cryptography to track transactions; it was
created to address the problems associated with the centralization of
digital currency.
• Traditional digital currencies are regulated by central banks and
governments (in much the same way as fiat currencies). This means all
transactions and exchange rates are determined by these two bodies.
Crypto currency has no state control and all the rules are set by the
crypto currency community itself.

149
• Unlike existing digital currencies, crypto currency transactions are
publicly available and therefore all transactions can be tracked and the
amount of money in the system is monitored.
• The crypto currency system works by being within a block chain
network which means it is much more secure.

Block chain
• Block chain is a shared, immutable ledger that facilitates the process
of recording transactions and tracking assets in a business network.
• The Block chain is a decentralized database with a growing list of data
blocks.
• It is basically a large digital ledger (like a spreadsheet) for recording
information in a way that makes it difficult or impossible to change,
hack, or cheat the system.

BLOCK
• Whenever a new transaction takes place, a new block is created: the
block contains data relating to the sender and recipient, the amount of
money, the currency used etc.
• The block contains a timestamp, the "HASH"...this is a unique
identifier generated by a Cryptographic Algorithm (SHA256), which acts
like a digital fingerprint.
• The block also as the HASH Value from the previous block in the chain
hence the name.
• This method of data storage is called NON-DESTRUCTIVE, meaning old
data never gets erased or overwritten. More blocks just keep getting
added.

150
Block chain

• Whenever a new transaction takes place, all the networked


computers get a copy of the transaction; therefore it cannot be
changed without the consent of all the network members. This
effectively removes the risk of security issues such as hacking.
• Each block in the chain contains transactions, and every time a new
transaction occurs on the block chain, a record of that transaction is
added to every participant's ledger.
• The decentralized database managed by multiple participants is
known as Distributed Ledger Technology (DLT).
• Block chain is used in many areas like Land records, Medical records,
Voting records and Smart records.

Future plan of block chain


• This new technology is transforming industries in a variety of ways. It
provides an automated process for business transactions and financial
record-keeping.

151
• This provides a cheaper and faster solution that is very attractive for
banks and businesses.
• As this new technology becomes more prevalent and advancements
are made, many changes are coming for business and our way of life.
1. Governments and Crypto currency
• It is likely that governments will eventually move from fiat currency to
crypto currency for a number of reasons. Crypto currency is more
traceable, has reduced settlement times and is overall more efficient.
• Like fiat currency, crypto currency can also be backed by real assets,
and its price can be manipulated through various controls.
• This is not unlike the practice of printing more money to deflate the
value of a dollar.
2. Greater transparency between businesses and industries
• In the very near future, there is likely to be a single block chain that is
shared between various industries.
• Having a single system will makes it easier and more accessible to the
public and provides greater transparency as well as trusted security.
3. Digital Identities - Passports
• Identity systems are currently flawed in many of ways. But block
chain systems can provide a single source to verify identity and assets.
• Block chain identity could also offer a type of "self-sovereignty" that
hasn't existed before.
• According to statistics, nearly 1.5 billion people throughout
developing nations have inadequate means of proving their identity. An
international block chain identification platform could offer

152
disenfranchised individuals the ability to access legal documentation
and the privileges that come with it.
4. The World Economy
• International trade is sometimes an inefficient and dysfunctional
process that slows down commerce and stops trade between nations.
International trade is also fraught with fraud, counterfeiting, corrupt
politics and errors.
• But with crypto currency, many of these problems could vanish. By
unifying methods of payment, paperwork and regulation through a
single digital international system, much of the fraud and inefficiency
can be eliminated.
• This should increase international commerce and provide greater
trust between nations.

Cyber security threats


1. Brute-Force Attack
• A 'trial and error' method used by cybercriminals to crack passwords
by finding all possible combinations of letters, numbers and symbols
until the password is found.
• One way to reduce the number of attempts needed to crack a
password is to try with the more commonly password first.
• The longer a password is and the greater the variation of characters
used, the harder it will be to crack.
2. Distributed Denial of Service (DDOS)
• A denial of service (DoS) attack is an attempt at preventing users from
accessing part of a network, notably an internet server.

153
• The attacker may be able to prevent a user from:
 Accessing their emails.
 Accessing websites or web pages.
 Accessing online services (such as banking).
If too many people accessing a website at the same time, the server will
go down.
How does it attack?
1. When a user enters a website's URL in their browser, a request is
sent to the web server that contains the website.
2. The server can only handle a finite number of requests. (Say: 1
million) at a time.
3. A criminal can use a software that force thousands of innocent
computers around the world to send a viewing request to a web
server.
4. The server becomes overloaded and won't be able to service a
user's legitimate request. It will slow the website down or cause it
to go offline altogether.
Signs to detect a DDOS attack
1. Slow network performance (opening files or accessing certain
websites).
2. Inability to access certain websites.
3. Large amounts of spam email reaching the user's email account.
4. Data Interception
• Data interception is a form of stealing data by tapping into a wired or
wireless communication link.
• The intent is to compromise privacy or to obtain confidential
information.

154
• Interception can be carried out using a packet sniffer, which examines
data packets being sent over a network. The intercepted data is sent
back to the hacker.
To tackle data interception
1. Encryption of data. E.g. Wired Equivalency privacy (WEP).
2. It is important not to use Wi-Fi (wireless) connectivity in public
places (such as an airport) since no data encryption will exist and
your data is then open to interception by anyone within the place.
5. Hacking
• Hacking is the act of gaining illegal access to a computer system
without the user's permission.
• Data can be deleted, passed on, changed or corrupted.
• Encryption cannot stops hacking but it can make use less for hacker.
• Data can be deleted, passed on, changed or corrupted. Encryption
does not stop hacking, it just make the data meaningless.
• Solution: Firewall, strong passwords.
6. Malware
Malware are pieces of software that have been written and coded with
the intention of causing damage to or stealing data from a computer or
system.
There are several types of malware:
 Virus
 Trojan horse
 Worm
 Spyware
 Adware

155
 Ransom ware
 Virus
• Viruses are programs or program codes that self-replicate with the
intention of deleting or corrupting files, or causing a computer to
malfunction.
• Viruses need an active host program on the target computer or an
operating system that has already been infected, before they can
actually run and cause harm.
• Viruses are often sent as email attachments, reside on infected
websites or on infected software downloaded to the user's computer.
 Trojan horse
• A Trojan horse is malware that is hidden away in the code of software
that appears to be harmless. A Trojan horse replaces all or part of the
legitimate software with the intent of carrying out some harm to the
user's computer system.
• They need to be executed by the end-user. They usually arrive as an
email attachment or are downloaded from an infected website.
• Once installed on the user's computer, the Trojan horse will give
cyber criminals access to personal information on your computers, such
as IP addresses, passwords and other personal data. Spyware and
ransom ware are often installed on a user's computer via Trojan horse
malware.
 Worm
• A type of stand-alone malware that can self-replicate. Unlike viruses,
they don't need an active host program to be opened in order to do any
damage.

156
• Worm replicates itself until the computer's resources are used to
their maximum capacity and no further processing can take place,
leading to system failure and crashing.
• Worms tend to be problematic because of their ability to spread
throughout a network without any action from an end-user; whereas
viruses require each end-user to somehow initiate the virus.
 Spyware
• Spyware is software that gathers information by monitoring a user's
activities carried out on their computer.
• The gathered information (bank account numbers, passwords and
credit or debit card details) is sent back to the cybercriminal who
originally sent the spyware (just like cookies)."
• Spyware can be detected and removed by anti-spyware software.
 Adware
• Adware is a software that will attempt to flood an end-user with
unwanted advertising.
• For example, it could:
 Redirect a user's browser to a website that contains promotional
advertising.
 Appear in the form of pop-ups.
 Appear in the browser's toolbar and redirect search requests.

 Ransom ware
• Ransom ware are programs that encrypt data on a user's computer
and 'hold the data hostage'.
• The cybercriminal waits until the ransom money is paid and,
sometimes, the decryption key is then sent to the user.

157
7. Phishing
• Sending out legitimate-looking emails designed to trick the recipients
into giving their personal details to the sender of the email.
• These emails may contain links or attachments, when initiated, take
the user to a fake website to enter personal details.
Ways to prevent phishing
1. Be aware of fake emails (eg. Dear (Your name) and not Dear
Customer).
2. Look out for http(s) in the address bar.
3. Be very wary of pop-ups and use the browser to block them.
8. Pharming
• Redirect user from a genuine website to a fake one, with the hope
that this goes unnoticed. They manipulate the DNS server.
• A user may then be prompted to enter login details, and this can then
be collected by a criminal for use on the genuine site.
• Pharming attacks occur when web servers are attacked, and code is
inserted into a website that redirects visitors (changing the IP address).
9. Social Engineering
• This form of cyber-crime is where users are manipulated into
behaving in a way that they would not normally do.
• Five common types of threat:
 Instant messaging (malicious link embedded in message).
 Scare ware (tell you that your computer is infected with virus).
 Email (genuine looking emails but not genuine).
 Baiting (leave a pen drive where it can be found).
 Phone calls (asks you to download special software).
• All threats above are effective methods for introducing malware.

158
• The whole idea of social engineering is the exploitation of human
emotion (fear, curiosity, empathy and trust).
Access Level
• This method of protection is hugely important in organizations where
there are lots of users accessing a network (eg. Havil Computer Lab).
• User will be assigned different levels of access depending on the role
they have. It ensures that users' behavior can be controlled while they
use a computer on a network.
• When using databases, levels of access are important to determine
who has the right to read, write and delete data.
Anti-malware
• Danger of malicious software.
 Theft of company data.
 Corruption of data (data becomes unreadable).
• Hence, a network should have anti-malware and anti-virus
applications installed that protect all devices on the network (just like a
vaccine to covid).
Types of Anti-malware:
 Anti-Virus
 Anti-Spyware
Anti-virus
• Anti-virus software are constantly scanning documents, files and also
incoming data from the internet.
• They are designed to detect suspicious activity and files before they
are opened or stored / warn the user against opening the files.

159
• If a file is detected as harmful, the anti-virus will quarantine the file
away from the network, preventing it from installing or multiplying
itself to other areas of the network or the hard disk drive.
• Upon user instructions, the software will then remove and delete the
offending malware or virus.
Anti-spyware
• Spyware: Spyware is software that gathers information by monitoring
a user's activities carried out on their computer.
• How they work:
 Looks for typical features which are usually associated with
spyware thus identifying any potential security issues
 File structures - in this case, there are certain file structures
associated with potential spyware which allows them to be
identified by the software.
Authentication
• Authentication refers to the ability of a user to prove who they are.
 Password and user names
 Biometrics Authentication
 Two-step verification
 Credit Card & Hotel Card
1. Password and user names
• Examples of where password is used:
 Websites.
 Mobile phones, etc.
• Password should be strong enough to stop criminals from guessing
them.

160
2. Tips for a stronger password
• Combine different types of character (lowercase, uppercase, special
character).
• Don't put in pattern in your passwords (eg. cabbag3), use random
patterns eg. Hp3oe7Ls* (!kajmc).
• Don't use the same passwords for all accounts.
• Be aware of spyware that tries to steal your passwords (via keyboard
stroke).
3. Two-step verification
• Requires two methods of authentication to verify who a user is.
• Example: Online shopping.
 Step 1: Enter user name and password.
 Step 2: Enter PIN that is sent back to her either in an email or as
a text message to her mobile phone.
4. Credit Card & Hotel Card
• Hotel card has magnetic stripe on the back of the card. These stripe
will store personal information.
• Credit card (or any smart card) has a chip that is read when inserted
into an Electronic Funds Transfer Point of Sale. The chip can hold a lot
of information (e.g. Pin).
Automating Software Updates
• This ensures that applications like operating systems, anti- virus and
other commonly used pieces of software are always operating with the
latest version installed.
• Greater threats are constantly evolving and that anti-virus companies
are always attempting to stay up to date with new attacks.

161
Spelling and Tone in communications
• Phishing emails are a threat to security. Sending out legitimate-
looking emails designed to trick the recipients into giving their personal
details to the sender of the email.
• Check
 If there is spellings errors in the email.
 The tone used in the email message.
Firewall
• A firewall can be either software or hardware. It sits between the
user's computer and an external network (for example, the internet)
and filters information in and out of the computer.
• Firewalls are the primary defense to any computer system to help
protect it from hacking, malware (viruses and spyware), phishing and
pharming.
• Main tasks are:
 Examine the 'traffic' between user's computer (or internal
network) and a public network.
 Checks whether incoming or outgoing data meets a given set of
criteria. If the data fails the criteria, the firewall will block the
'traffic'
 Criteria can be set so that the firewall prevents access to certain
undesirable sites; the firewall can keep a list of all undesirable IP
addresses.
• The firewall can be software installed on a computer; in some cases, it
is part of the operating system.

162
Privacy Setting
• Privacy settings are the controls available on web browsers, social
networks and other websites that are designed to limit who can access
and see a user's personal profile.
• Examples:
 "Do not track" setting.
 Allow payment method to be saved (avoid the need to key in
information every time, which is dangerous).
 Safer browsing.
 App (sharing of location).
Proxy Server
• Proxy servers act as an intermediate between a user and a web
server.
• Benefits:
 Allows internet traffic to be filtered; it is possible to block access
to a website if necessary - Parental Control.
 Keeps users' IP addresses secret which improves security
(middleman concept).
 If an attack is launched, it hits the proxy server instead - this
helps to prevent hacking, DDOS, and so on.

Secure socket layer


• SSL is a protocol or rule that is commonly found on websites where
financial transactions take place.

163
• SSL encrypts the connection between the user's computer and the
website that is being used. Sensitive data can be bank card numbers,
login details and passwords.
Secure Socket Layer hand shake – flow
HahahahahahahahahahaHa hahahahahahaha hahaHahahahahahaha hahaha Hahahahahahaha hahahaHahahahaha ha hahahahaHahahaha hahahahahaha Hahaha hahahahahahahaHaha hahahahahahaha haHahahahahahahahahaha Hahaha hahahahahahahaHaha hahahahahahaha ha Hahahahahahaha hahaha Hahahahahahaha hahahaHahahahaha hahahahahaHahahaha hahahahahaha Hahahaha hahahahahah aHahahahahahahahahahaHaha haha hahahahaha ha Hahahahahahahahaha haHahahahahahahaha hahaHahahahahaha hahahaha Hahahahahaha hahahahaHahahaha hahahahahahaHahaha hahahahaha haha HahahahahahahahahahaHahaha hahahahahahahaHaha hahahahahahaha ha Hahahahahahahahaha haHahahahahahaha hahahaHahahahahaha hahahaha Hahahah
ahahahahahahaHahahahaha hahahahahaHahaha hahahahahahaha Hahaha hahahahahahahaHaha hahahahahahaha haHahahahahahaha hahaha Hahahahahahaha hahahaHahahahahaha hahahahaHahahaha hahahahahaha Hahahahaha hahahahahaHahahaha hahahahahahaHaha hahahahahahaha ha Hahahahahahahahaha ha Hahahahahahahaha hahaHahahahahaha hahahaha Hahahahahaha hahahahaHahaha hahahahahahahaHahaha hahahahahahaha Hahaha hahahahahahahaHa hahaha hahahaha hahaHahahahahahaha hahaha Hahahahahahaha hahahaHahahahaha hahahahahaHahahaha hahahahahaha Haha hahahahahahahahaHaha hahahahahaha ha haHahahahahahahaha haha Hahahahahahaha hahahaHahahahahaha hahahahaHahahaha hahahahahaha Hahahaha hahaha
hahahaHahahahahahaha hahahaHaha hahaha hahahahaha Hahahahaha hahahahahaHahahaha hahahahahahaHaha hahahahahahaha ha Hahahahahahahahaha haHahahahahahahaha hahaHahahahahaha hah ahaha HahahahahahahahahahaHa hahahahahahahaha haHahahahahahaha hahaha Hahahahahahaha hahahaHahahahaha hahahahahaHahahaha hahahahahaha Hahahaha hahahahahahaHaha hahahahah ahahahaHahahahahahahaha haha Hahahahahahahaha hahaHahahahahaha hahahahaHahahahaha hahahahaha Hahahaha hahahahahahaHahaha hahahahahahahaHa hahahahahahahaha ha Hahahahahah ahahahahaHahahahahahaha hahahaHahahahaha hahahahaha Hahahahaha hahaha hahaHahahaha hahahahahahaHaha hahahahahahaha ha Hahahahahahahahaha haH
ahahahahahahahahahaHaha hahahahahahaha ha Hahahahahahahahaha haHaha hahahahaha hahahaHahahahahaha hahahaha Hahahahaha hahahahahaHahahaha hahahahahahaHahaha hahahahahahaha HahahahahahahahahahaHahaha hahaha hahahahaHaha hahahahahahaha ha Hahahahahahahahaha haHahahahahahaha hahahaHahahahahaha hahahaha Hahahahaha hahahahahaHahahaha hahahahaha ha Hahahahahahahahahaha Haha hahahahahahaha haHahahahahahahaha hahaHahahahahahaha hahaha Hahahahahaha hahahahaHahahahaha hahahahahaHahaha ha hahahahahaha Hahaha hahahahaha hahaHahahahahahahahaha haHahahahahahaha hahaha Hahahahahahaha hahahaHahahahahaha hahahahaHahahaha hahahaha haha Hahahaha hahahahahahaHaha haha
hahahahahahaHahahaha hahahahahaha Hahahaha hahahahahahaHaha hahahahahahaha haHahahahahahahaha haha Hahahahahahahaha hahaHahahahahaha hahahahaHahahahaha hahahahaha Hahaha hahahahahahahaHahaha hahahahahahahaHa hahahahahahahaha ha Hahahahahahahaha hahaHahahahahahaha hahahaHahahahaha hahahahaha Hahahahaha hahahahahaHahahaha hahahahahahaHaha hah ahahahahahaha Hahahahahaha hahahaha Hahahahaha hahahahahaHahaha hahahahahahaha Hahaha hahahahahahahaHa hahahahahahaha hahaHahahahahahaha hahaha Hahahahahahaha hahahaHahah aha hahahahahahaHahahaha hahahahahaha Hahahaha hahahahahahaHaha hahahahahahaha haHahahahahahahaha haha Hahahahahahaha hahahaHahahahahaha hah
ahahaHahahahahahahahaha

The user's browser The browser The web server


sends a message so then requests responds by
that it can connect that the web sending a copy
with the required server of its SSL
website which is identifies itself. certificate to
secured by SSL. the user's
browser.
Once this message
is received, the
web server
If the browser can authenticate
acknowledges the
this certificate, it sends a
web browser, and
message back to the web server
the SSL- encrypted
to allow communication to begin.
two-way data
transfer begins.

164
Automated & Emerging Technologies
chapter 13
Definition of automated system
A combination of software and hardware that is designed and
programmed to work automatically without the need of any human
intervention.
The hardware that are need in an automated system are
Microprocessor

The microprocessor processors the input from the sensors (eg. check if
input values exceed preset values). If necessary, it will send instructions
to other components such an actuator.
Sensor

Input devices that take readings from their surroundings and send this
data to a microprocessor or computer. If the data is analogue, it is first
converted into a digital format by an analogue-digital converter (adc).

165
Actuator

Turns electrical signals (sent by microprocessor) into physical outputs


such as movements.
Application of automated system in the real world
 Transport  Agriculture
 Weather  Gaming
 Lighting  Science

Transport  Industry

Automatic Transport
• Autonomous cars use sensors, cameras, actuators, and
microprocessors to carry out their actions safely.
• Microprocessors process the data received from cameras and sensors
and send signals to actuators to perform physical actions, such as
change gear, apply the brakes and turn the steering wheel.
Advantages and disadvantages
Advantages disadvantages
• Safer since human error is • Very expensive system to set up
removed due to fewer accidents. in the first place.

166
• Better for the environment • The ever-present fear of hacking
since vehicles will operate more into the vehicle's control system.
efficiently.
Agriculture
Automatic harvesting of crops.
• Sensors detect optimal times for harvesting based on factors such as
weather conditions.
• Microprocessors determine exact locations for the harvest.
• Actuators are used to carry out the extraction of goods from the
ground.
Advantages and disadvantages
Advantages disadvantages
• Delivery of chemicals (pesticide • Fewer job opportunities as
and fertilizer) can be given humans are increasingly replaced
accurately, which is important to by machinery. The robots can also
the success of farming and crops. be expensive.
Weather
• Automated monitoring of weather at airports to help predict poor
flying and landing conditions.
• Sensors check for potentially dangerous weather such as wind, rain,
fog or snow, microprocessors are programmed to issue relevant
warnings as a result of the data gathered.
• Actuators can activate emergency systems such as lighting wherever
required.

167
Advantages and disadvantages
Advantages disadvantages
• Information about the overhead • Predictions can sometimes be
weather conditions is fed incorrect, for example if snow is
constantly to air traffic forecast and does not arrive.
controllers.
Gaming
• The introduction of artificial intelligence as opponents in computer
games.
• Sensors are built into gaming environments where characters interact
with human controllers,
• Microprocessors determine game outcomes and decisions.
• Actuators are activated in controllers to give haptic feedback.
Advantages and disadvantages
Advantages disadvantages
• The depth of gaming challenge • Decreases real social
is increased with computer- interactions with other humans
generated opponents who and can create an almost fictional
behave in a 'human' way. life.
Lighting
• Lighting control systems in a house where routines can be present
based on behaviors.
• Sensors can detect ambient light levels.
• Microprocessors run routines based on human requirements.
Actuators can activate home equipment.

168
Advantages and disadvantages
Advantages disadvantages
• System can be taught to react • Systems can become complex
to environmental factors, such as as they are different from
switching lights on and off when traditional switches. The light
the conditions are correct. bulbs and technology also tend to
be expensive to maintain.
Science
• Automated laboratory experiments that can be carried out
continuously over many days.
• Sensors detect changes in environmental conditions.
• Microprocessors can calculate required alterations to the
experimental settings.
• Actuators can turn on heaters, coolers or water supplies as required.
Advantages and disadvantages
Advantages disadvantages
• Many more repetitions of • If something goes wrong several
experiments and reading of data hours before the discovered,
can take place than when humans which could affect results
carry out tests manually. collected.
Industry
Advantages and disadvantages
Advantages disadvantages
• Robots are capable of working • Robots can lead to higher
in conditions that may be unemployment amongst manual
hazardous to humans. labor tasks.

169
• Robots work 24/7 without the • There is a risk of deskilling when
need to stop. robots take over certain tasks.
Characteristics of a robot
1. It has electrical components
• A robot should have a combination of sensors, a microprocessor and
actuators.
• Sensors sense the surrounding, microprocessor processes the input
data, and actuators do the work.
2. It has mechanical structures
• It should be a machinery that has movable parts.
• e.g. They can make use of wheels, cogs, pistons, and gears (etc.) to
carry out functions such as turning, twisting, moving
backwards/forwards, gripping or lift.
3. It is programmable
• Robots have brain known as a controller that determines the action
to be taken to perform a certain task
• Controllers
 Rely on input data from the sensors.
 Are programmable to allow the robots to do certain tasks.

Knowledge in robots
• Independent robots have no direct human control (they are said to
be autonomous, for example, an autonomous vehicle).
• Dependent robots - have a human who is interfacing directly with the
robot (the human interface may be a computer or a control panel).

170
Robots are used in following fields
 Transport  Agriculture
 Industry  medicine
 Domestic  Entertainment

Transport
Advantages and disadvantages
Advantages disadvantages
• Safer since human error is • Very expensive system to set up
removed due to fewer accidents. in the first place.
• Better for the environment • The ever-present fear of hacking
since vehicles will operate more into the vehicle's control system.
efficiently.
Agriculture
Descriptions:
• Robots could replace slow. Repetitive and dull tasks allowing farmers
to concentrate on improving production yields.
Advantages and disadvantages
Advantages disadvantages
• Delivery of chemicals (pesticide • Fewer job opportunities as
and fertilizer) can be given humans are increasingly replaced
accurately, which is important to by machinery. The robots can also
the success of farming and crops. be expensive.

171
Medicine
Descriptions:
• Robots can be used during surgeries to perform complex procedures
with more precision, flexibility and control. They can also be used to
monitor vital life data, in research and development such as tissue
engineering, in the replacement of limbs such as bionic prosthetics
(artificial limbs) and to simulate certain medical environments and tasks
for training purpose.
• Robots can take blood samples from patients:
 Less painful to patients since the robot is better at determining a
'good vein' safer to doctors and nurses if the patient has an
infectious disease.
 Doctors and nurses can be freed up to do more skilled work.
Advantages and disadvantages
Advantages disadvantages
• Surgery can take less time, • This technology is expensive
which improves the chances of and has to be tested extensively
recovery for the patient. in research before it is used on
humans.
Domestic
Descriptions:
• Traditional household appliances like vacuum cleaners and
lawnmowers are being replaced by robotic versions.
Examples:
 Autonomous vacuum cleaner.
 Autonomous grass cutter.
 Personal assistant (eg. alexa).

172
Advantages and disadvantages
Advantages disadvantages
• Robots can quickly learn the • This can encourage a more
environment. They can be sedentary lifestyle.
programmed to work at
convenient times.
Entertainment
Advantages and disadvantages
Advantages disadvantages
• Film can be presented in ways • Fewer job opportunities as
that a human would not be able humans are increasingly replace
to normally see due to robotic by machinery.
technology.
AI definition
A branch of computer science dealing with the simulation of intelligent
human behavior (reasoning, speech, sight) by a computer.
What exactly is intelligence?
Intelligence is the ability to think, to learn from experience, to solve
problems, and to adapt to new situations. Intelligence is important
because it has an impact on many human behaviors.
Two main methods of training device for AI
Method 1. Draw a reasoned conclusion razed on given data .To train
computer for something you have to give some data. For example make
a graph, write prices at y-axis and products on x-axis.
Method 2. By carrying out a sequence of steps (asking some questions).
The AI machine can learn, and next time it will know how to do the task
more effectively and even apply it to a novel/new situation. For
example symptom checker.

173
Expert system
A computer system that mimics the decision-making ability of a human.
It simulates the judgment (using knowledge and experience) and
behavior of a human or organization that has expert knowledge and
experience.
Structure of an expert system
At first users interacts to user interface.

User interface
How a user communicates and interacts with the
expert system. The system will often ask questions
that require an answer or a button press.
Knowledge base
Stores all the knowledge about an area of expertise
obtained from a number of expert resources.
A set of inference
Rules used by inference engine to draw conclusion.
1. Searches the interact knowledge base for
information/data that matches the queries
2. Make use of inference rule in the rule base.
3. Produce possible solutions to a problem.
Types of conclusion given:
1. suggested action to take.
2. Accuracy of its prediction.
It will tell the conclusion and tell a percentage e.g.
there is 80% chance that you have this disease.

174
Advantages and disadvantages of an expert system
Advantages disadvantages
1. High level of expertise. 1. Set up and maintenance costs
2. High accuracy. are very high.
3. consistent result, 2. They are only as good as the
4. Have the ability to store vast information entered into the
amounts of ideas and facts. system.
5. They have very fast response
time.
Machine learning
Algorithms are 'trained' and learn from their past experiences and
examples. They don't need to be specifically programmed. They can
make predictions about new unseen data.

Process of Machine learning


A machine learning Carries out a cleaning
algorithm collects process to remove
data about emails. stop words (the, an, a)

The machine learning model is Certain words/ phrases


built and a training data set is used are frequently used in
to train the model and make it email that could indicate
using past emails known to be that the incoming email
spam. Once it is evaluated, the is very likely to be spam
model is fine-tuned and tested live. (lottery, earn, full-refund.

175
Cloud & encryption chapter 14
Cloud Storage
Public and private cloud computing.
• Cloud storage is a method of data storage where data is stored on
remote servers over the internet.
• The same data is stored on more than one server in case of
maintenance or repair, allowing clients to access data at any time and
from anywhere in the world with an internet connection. This is known
as data redundancy.
• The physical environment is owned and managed by a hosting
company and may include hundreds of servers in many locations.
Benefits and drawbacks of cloud storage
Benefits of using cloud storage Drawbacks of using cloud storage
• Users files stored on the cloud • If the user has a slow or
can be accessed at any time from unstable internet connection,
any device anywhere in the world they would have many problems
provided internet access is accessing their files.
available. • Costs can be high if large
• There is no need for a user to storage capacity is required; it can
carry an external storage device also be expensive to pay for high
with them, or even use the same download or upload data transfer
computer to store and retrieve limits with the user internet
information. service provider (ISP).
• The cloud provides the user
with remote backup of data with
obvious benefits to alleviate data
loss/disaster recovery.

176
• If a user has a failure of their • The potential failure of the
hard disk, cloud storage will allow cloud storage company is always
recovery of their data. possible- this poses a risk of loss
• The cloud system offers almost of all backup data.
unlimited storage capacity.

Encryption
• Encryption is the process of encoding data or a message so that it
cannot be understood by anyone other than its intended recipient.
• In computer processing, encryption means that data can be stored
and transmitted securely by the sending computer to the receiving
computer. The data or message is encrypted using an encryption
algorithm. The opposite of encryption is decryption.
Use of encryption
• Most communications sent via the internet are encrypted in some
way:
• Purchases made online are encrypted to try to prevent theft of credit
card details.
• Tools enable a user to encrypt a document, such as a spreadsheet,
before sending it to a colleague via the internet.
• Satellite TV transmissions are encrypted to prevent users who do not
subscribe from watching TV shows.
Plaintext and Cipher text
• The original data being sent is known as plaintext. Once it has gone
through an encryption algorithm, it produces cipher text.

177
Encryption Types
There are two types of encryption:
 Symmetric Encryption
 Asymmetric Encryption
Symmetric Encryption
• In Symmetric-Key encryption the message is encrypted by using a key
and the same key is used to decrypt the message which makes it easy
to use but less secure.
• It also requires a safe method to transfer the key from one party to
another. Communicating parties must have the same key in order to
achieve secure communication.
Asymmetric Encryption
• In today's digital world, there has been a need to develop a different
approach to encryption, called asymmetric encryption. With this
approach a pair of linked keys is used and consists of a public key, used
to encrypt data and of private key used to decrypt data. Both keys are
different (but related).
• The public key, is available to everyone who wishes to send a
message. On the other hand, the private key is kept at a secure place by
the owner of the public key.
Symmetric Key Encryption Asymmetric Key Encryption
• It only requires a single key for • It requires two key one to
both encryption and decryption. encrypt and the other one to
decrypt.
• The size of cipher text is same • The size of cipher text is same
or smaller than the original plain or larger than the original plain
text. text.

178
• The encryption process is very • The encryption process is slow.
fast.
• It is used when a large amount • It is used to transfer (small
of data is required to transfer. amount of data.
• It only provides confidentiality. • It provides confidentiality,
authenticity and validation.
• Examples: 3DES, AES, DES and • Examples: Diffie-Hellman, ECC,
RC4 El Gamal, DSA and RSA
The Internal System Clock
The main components of the CPU are the:
 Control unit (CU).
 Arithmetic and logic unit (ALU).
 Registers and buses.
There is also a System Clock
• The clock sends out a regular electrical pulse which synchronizes
(keeps in time) all the components.
• The frequency of the pulses is known as the clock speed Clock speed
is measured in hertz. The higher the frequency, the more instructions
can be performed in any given moment of time.
• Processors commonly run at a rate of 3 gigahertz (GHz) to 5 GHz,
which is 3 billion to 5 billion pulses or cycles per second.
• The CPU can be over clocked to increase performance. But
overclocking problems can occur due to increase in heat that can result
in instability and damage to the processor. The fan is having to work
harder to dissipate the heat.

179
Cores
• The "core" of the CPU is like the cerebral cortex (back bone) - it's the
most crucial part that actually carries out the instructions. When you
hear about an "Intel Dual Core", this refers to two cores.
Single Cores
• Older desktop PCs have what are called single-core CPUs. That means
the CPU can only execute one instruction at a time. If you're doing a ton
of multitasking, have a lot of apps open, or are playing a computer-
intensive game, having a single-core CPU can be a serious bottleneck!
Even today, some laptops, especially netbooks, are made with single-
core CPUs, making them unsuitable for anything other than word
processing and light web browsing.
How Many CPU Cores Do You Need?
• Single-cores are not recommended.
• Dual-core CPUs for basic tasks, word processing, browsing, and light
gaming.
• Quad-core CPUs for acceptable gaming performance and responsive
operation.
• Six-core CPUs are the sweet spot for gaming, it is cheap and solid for
productivity work.
• Eight-core CPUs are amazing at all tasks. Great for productivity work
and heavy gaming.
• Ten or more core CPUs scale greatly in price, and are recommended
only for those that rely on productivity work.

180
Instruction Sets
• All computer software is built up of sets of instructions. Instructions
are encoded in binary. The fetch-decode-execute cycle is the sequence
of steps that the CPU follows to process instructions.
• Instructions are decoded as a set of sequenced operations. These
operations instruct the ALU and control unit inside the CPU.
Opcode
• The opcode tells the processor the job that needs to be done. A
simple operation might be 'add or subtract. If we use the analogy of a
recipe, the opcode might be 'chop' or 'mix'.
Operand
• The operand specifies the data that needs to be acted on. The
operand can also refer to a place in memory, such as a register.

181
Algorithm design & problem solving
chapter 15
Algorithms
• An algorithm is a set of instructions / steps / rules that are followed to
solve a problem.
We follow algorithms every day, maybe without even realizing we are doing so, you have a
routine for cleaning your teeth (unlike me 😂). You follow a series of memorized steps when
making a drink of tea Cookery books have pages full of algorithms.

The program Development life cycle


The program development life cycle is divided into SIX stages: analysis,
design, coding and testing.

Step 1: Step 2: Step 3:


Problem Problem Algorithm
Definition Analysis Developm
ent

Step 6: Step 5: Step 4:


Maintenance Testing & Coding &
Debuggin Document
g ation
• But we are going to focus on Problem Analysis, Algorithm
Development, Coding & Documentation and Testing & Debugging.
 Analysis: abstraction, decomposition of the problem,
identification of the problem and requirements.
 Design: decomposition, structure diagrams, flowcharts, pseudo
code.
 Coding: writing program code and iterative testing.

182
 Testing: testing program code with the use of test data.
Problem Analysis
• Before any problem can be solved, it must be clearly defined so that
everyone working on the solution understands what is needed. This is
called the 'Problem Definition' or 'Requirement Specification for the
program. This is called computational thinking.
• The 'Problem Analysis' phase uses abstraction, pattern recognition
and decomposition tools to identify exactly what is required of the
program.
Specific details or characteristics
Example one
• In pattern recognition we looked at the problem of having to make a calculator.
We noted that all buttons in the calculator have few general characteristics e.g. all
are made of plastic most have same size and color.
• In addition, each dog has specific characteristics, such as + sign, – sign, number
0, number 1, number 2, number 3 and so on… These details are known as
specifics.
• In order to make a basic calculator, we do need to know (Zero Is the Only
Number That Can't Be Represented In Roman Numerals.) These characteristics
are irrelevant and can be filtered out. We do need to know that a button in
calculator has different numbers and symbols written on it.
Specific details or characteristics
Example two
• In pattern recognition we looked at the problem of having to draw a series of
dogs. We noted that all dogs have general characteristics, which are common to
all dogs, e.g. eyes, a tail, fur, a liking for sniffing bottoms and the ability to make
barking sounds.

183
• In addition, each dog has specific characteristics, such as black fur, a long tail,
green eyes, a love of fetching sticks, and a loud bark. These details are known as
specifics.
• In order to draw a basic dog, we do need to know that it has a tail, fur and eyes
because these characteristics are relevant. We don't need to know what sound a
dog makes or that it likes chasing cars and retrieving sticks. These characteristics
are irrelevant and can be filtered out. We do need to know that a dog has a tail,
fur and eyes, but we don't need to know what size and color these are. These
specifics can be filtered out.
• From the general characteristics we have (tail, fur, eyes) we can build a basic
idea of a dog, i.e. what a dog basically looks like. Once we know what a dog looks
like we can describe how to draw a basic dog.
Decomposition
• Breaks down a complex problem into smaller parts, which can then
be broken down into even smaller parts that can be easily solved. Each
daily task can be divided into individual parts.

Program Development
• A program specification from the problem analysis stage is used to
show to how the program should be developed.
• When the design stage (Algorithm Development) is complete, the
programmer should know what is to be done, i.e. all the tasks that need
to be completed and how each task is to be performed, including how
the tasks work together.
• This can be formally documented using structure charts, flowcharts
and pseudo code.

Coding & Documentation


• At this stage the program or set of programs is developed.

184
• Each module/part of the program is written using a suitable
programming language and then it would be tested to see if it works.
• Iterative testing is done which means that modular tests are
conducted, code is amended, and tests are repeated until the program
performs as it is required.

Testing & Debugging


• The now completed program or set of programs is run over and over
again, many times with different sets of test data.
• This ensures that all the tasks are debugged and work is completed
inline and as specified in the program design.

Computer systems, sub-systems and decomposition


• A computer system can be described as the software, data, hardware,
communications and people within; each computer system can be
divided up into a set of sub-systems.
• Each sub-system can be divided further into more sub-systems and so
on until each sub-system just performs a single action.
• Subsystems or subtasks are events or tasks that happen within a
system.
• For example a satellite navigation systems include:

185
• When you wake up in the morning, you might probably use an app on
your smartphone for your alarm, then you might check the weather
forecast on your computer before going to school.
• The alarm program is an example of a very small computer system
but when you check the weather forecast, you are obtaining the
information you need from one of the largest computer systems in the
world.

Structure diagrams that demonstrate the construction of


a system
• In order for someone to gain an understanding as to how a computer
system is built up and how it works it is often divided up into
subsystems and shown as a diagram.
• These diagrams include structure diagrams, flowcharts or pseudo
code.
• These are all effective ways to demonstrate the solution to a
problem, and how each part of the problem is broken down into
smaller more manageable problems.

Decomposing a problem
• Any problem that uses any kind of computer system for its solution
needs to be decomposed into its component parts. These component
parts of any computer system are:
 INPUT: The data used by the system that needs to be entered
while the system is active.
 PROCESS: The tasks that need to be performed using the input
data and any other previously stored data.
 OUTPUT: Information that needs to be displayed or printed for
the users of the system.

186
 STORAGE: Data that needs to be stored in files on an appropriate
medium for use in the future.

Structure diagrams
• These diagrams can be used to show examples of top-down design in
a diagrammatic form.
• Structure diagrams are hierarchical, showing how a solution can be
divided into sub-systems with each level providing a more detailed
breakdown.

Flowcharts
• A flowchart shows diagrammatically the steps required to complete
tasks and the order that they need to be performed. These steps,
together with the order of each of these steps, are called an algorithm.
• Flowcharts are a very effective way to communicate how the
algorithm that makes up a system or subsystem is broken down and
works.

Flowcharts symbols:

187
Terminator: (Begin/End) Input/Output: the same
flowchart symbols are flowchart symbol is used to
used at the beginning and show the input of data and
end of each flowchart. output of information.

Process symbols: ore used to show


Flow Lines: use arrows actions, for example, when values
to show the direction are assigned to variables. If a
of flow which is process has been defined
usually, but not elsewhere then the name of that
always, top to bottom process is shown.
and left to right.

Decision symbols: are used to


decide which action is to be
taken next these can be used
for selection and
repetition/iteration. There
are always two outputs from
a decision flowchart symbol.

188
Pseudo code
• This is a simple method of showing an algorithm by using English key
words that are very similar to those used in high-level programming
languages.
• Data items to be processed by the algorithm are given meaningful
names in the same way that variables and constants are in a high-level
programming language. However it is not bound by the strict syntax
rules of a programming language.
• However it is not bound by the strict syntax rules of a programming
language.

Thing you need to know


• Understand and use pseudo code for assignment, using 
• Understand and use pseudo code, using the following conditional
statements:

189
IF... THEN... ELSE... ENDIF
CASE OF OTHERWISE... ENDCASE
• Understand and use pseudo code, using the following loop structures:
FOR... TO... NEXT REPEAT UNTIL
WHILE DO... ENDWHILE
• Understand and use pseudo code, using the commands and
statements: INPUT and OUTPUT (e.g. READ and PRINT)
totaling (e.g. Sum  Sum + Number)
counting (e.g. Count + Count + 1)
• Understand and use standard flowchart symbols to represent the
above statements, commands and structures.
Assignment (using)
• Values are assigned to variable using the  operator.
• The variable on the left of the  is assigned the value of the
expression on the right.
Examples of pseudo code assignments:
Cost  29 Means Cost has the value 29
Price  Cost*2 Means Price has the value 58
Tax Price  0.19 Means Tax has the value 11.02
Selling Price  Price + Tax Means Selling Price has the value 69.02
Assignment (Mathematical Operators)
• The expression below can be a single value or several values
combined with mathematical operators.
Examples of Mathematical Operators:

190
Operators Action Example
+ Add 2+2
- Subtract 5–3
* Multiply 4*9
/ Divide 1/4
^ Raise to the power of 7^3
( ) Group 6*(5+8)
Conditional Statements
• When different actions are performed by an algorithm based on to
the variable's value, conditional statements can be used to decide
which action needs to be taken.
• We use two types of conditional statement as shown below with an
example of each.

IF THEN... ELSE... ENDIF...


• There are several different ways that an IF condition can be set
up....here are some examples including BOOLEAN and COMPARISON
OPERATORS (<, >, =, AND, OR NOT):

191
Rewriting code to show understanding

CASE OF OTHERWISE... ENDCASE


• For a CASE statement the value of the variable decides the path to be
taken. Several values or choices are usually provided. OTHERWISE is the
path taken for all other values. The end of the statement is shown by
ENDCASE.

192
LOOPS (Iteration) ⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
• All types of loops can all perform the same task, for example
displaying ten stars.

193
LOOPS: FOR... TO... NEXT

• A variable is set up, with a start value and an end value, this variable
is incremented in steps of one until the end value is reached and the
iteration finishes.
• The variable can be used within the loop so long as its value is not
changed.
• This type of loop is very useful for reading values into lists with a
known length.
LOOPS: REPEAT... UNTIL
• This loop structure is used when the number of repetitions/iterations
is not known and the actions are repeated UNTIL a given condition
becomes true.
• The actions in this loop are always completed at least once.
• This is a post-condition loop as the test for exiting the loop is at the
end of the loop.

194
LOOPS: WHILE ... DO... ENDWHILE
• This loop structure is used when the number of repetitions/iterations
is not known and the actions are only repeated WHILE a given condition
is true.
• If the WHILE condition is untrue then the actions in this loop are
never performed.
• This is a precondition loop as the test for exiting the loop is at the
beginning of the loop.

195
Input and output statements
• Input is used for data entry, it is usually followed by a variable where
the data input is stored, for example:

Input name

• Output is used to display information either on a screen or printed on


paper; it is usually followed by a single value that is a string or a
variable, or a list of values separated by commas, for example:

Your name is Affan.

Explaining the purpose of an algorithm.


• An algorithm sets out the steps to complete a given task; a little bit
like a recipe for baking a cake!
• It is usually shown as a list of instructions, a flowchart or pseudo code,
so that the purpose of the task and the processes needed to complete
it are clear to those who will use it.
• The more you practice these skills, the more familiar you will become
with writing, finding and correcting errors in algorithms.
• Example: - (The purpose of the pseudo code here is to output an
alarm sound at a set time.)
• The processes are:
 Waiting 10 seconds, getting the
current time.
 Checking the current time with
the alarm time, and outputting
the alarm sound when both
times match.

196
• Have a look at the flowchart and
pseudo code:
• What is the purpose of this
algorithm that they both represent?
• What are the processes included in
the algorithm.

Standard methods of solution


• It is very important in the design of algorithms to be able to repeat
existing methods for finding solutions/answers. Because when an
algorithm is turned into a program these may be repeated many
thousands of times. You need to be able to use the following standard
methods:
 Totaling.
 Counting.
 Finding maximum, minimum, and average (mean) values.
 Searching using a linear search.
 Sorting using a bubble sort.
Totaling
• Totaling means keeping a running
total from values which are being
added. For example, keeping a
running total of the marks awarded
to each student in a class.

197
Counting
• Keeping a count of the
number of times an action
takes place is another
standard method. For
example, counting the
number of students that
were awarded a pass grade.
Maximum, minimum and
average
• Finding the largest and
smallest values in a list
are two standard
methods that can
frequently be found in
algorithms, for example,
finding the highest and
lowest mark awarded to a
group of students.
Bubble Sort
• Lists can be more useful if the items are sorted in a meaningful order.
• For example, names could be sorted in alphabetical order, or
temperatures could be sorted in ascending or descending order.
-3 18 0 -7 5
In this example we have a list of numbers which need to be sorted in
ascending order.
1. Starting from the first element in the array, compare the first and
second elements.

198
2. If the first element is greater than the second element, swap the
elements.
3. Compare the second and third elements, swap them if they are not
in order.
4. Proceed with the above process until the last element.

Validation and Verification


• Validation and Verification are both used to ensure that data entered
into a computer system is correct and reasonable.
• The usual definitions are:
 Validation: ensures that only data that is reasonable is accepted.
 Verification: is used to check that the data does not change as it is
being entered.
Validation
• Validation is the automated checking by a program to ensure that the
data entered is sensible and reasonable.

199
• If the data is rejected while a computer system is validating, a
message should be output explaining why the data was rejected and
another opportunity given to enter the data. It does not check the
accuracy of data.
For example, a student in secondary school is aged between 11 and 16.
A computer can be programmed only to accept numbers between 11
and 16. This is a known as a range check.
However, this does not guarantee that the number typed in is correct.
For example, a student might be 14, but if 11 is entered it will be valid
but incorrect.
Types of Validation
• There are a number of validation types that can be used to check the
data that is being entered.
Validation type How it works Example usage
Check digit The last one or two Bar code readers in
digits in a code are supermarkets use check
used to check the other digits.
digits are correct. (it is
also explained in page
38 and 39)
Format check Checks the data is in A National Insurance
the right format. number is in the form LL
99 99 99 L where L is any
letter and 9 is any
number.
Length check Checks the data isn't A password which needs
too short or too long. to be six letters long.
Lookup table Looks up acceptable There are only seven
values in a table. possible days of the week.

200
Presence check Checks that data has In most databases a key
been entered into field. field cannot be left blank.
Range check Checks that a value falls Number of hours worked
within the specified must be less than 50 and
range. more then 0
Spell check Looks up words in a When word processing.
dictionary.
Range checks
• A range check is used to ensure that
numbers are only accepted into a
program if it falls within a certain
acceptable range.
• Example - If a program asks for
someone's age then you might limit
entries to be between 13 and 100. This
would potentially prevent people
under the age of 13 from signing up
and it would also prevent people
giving an unrealistic age e.g. 250 years
old.
Presence checks
• A presence check checks to ensure
that some data has been entered and
the value has not been left blank, for
example, an email address for an
online transaction must be completed.
• Example - An internet blog has the
ability to post comments. You do not
need to create an account, however
before the post is published you do

201
need to enter your name. In this case there are no rules about how long
or realistic your name should be. The only rule is that you have to enter
a name.
Length checks
A length check checks either:
• that data contains an exact
number of characters, for example
that a password must be exactly
eight characters in length so that
passwords with seven or fewer
characters or nine or more
characters would be rejected.
• or that the data entered is a
reasonable number of characters,
for example, a family name could
be between two and thirty
characters inclusive so that names with one character or thirty-one or
more characters would be rejected.
Format checks & check digits
• A format check is used to ensure that data entered matches a desired
pattern.
• If a user is required to enter an email address then it should follow a
set pattern: "XXXXX" + @+ "XXXXX" +":"+"XXX" This would allow an
email address such as "example@gmail.com" to be accepted.
• Another example of a format check would be to check that an ID
number has been entered in the correct format.
• A check digit is the final digit included in a code; it is calculated from
all the other digits in the code.

202
• Check digits are used for:

 Barcodes  ISBN Numbers


 product codes  VIN Numbers (Vehicle Identification)
Verification
• There are two main methods of verification:
 Double entry: entering the data twice, sometimes by different
operators. The computer system compares both entries and if
they are different outputs an error message requesting that the
data is entered again.
 Proofreading data: this method involves someone checking the
data entered against the original document. This is also time-
consuming and costly.
Using Test Data to check our code
• It is important to test algorithms to check how they perform under a
range of conditions.
• This includes testing any validation you have created to ensure it
performs as expected.
• When creating a testing plan, the test data that you use shouldn't be
random values, but rather values how it would be expected to perform,
it's upper or lower limits and data that should be rejected.
• Before performing a test, you need to decide what data you are going
to use. It is not always possible to perform tests with every single piece
of data. So, instead the developers will choose from a limited range of
data such as:
 Valid data - sensible, possible data that the program should
accept and be able to process.

203
 Extreme/boundary data - valid data that falls at the boundary of
any possible ranges and can be used to test what breaks the
program.
 Invalid (erroneous) data-data that the program cannot process
and should not accept.

Example of Valid Data Example of


If a program asks a user to enter Extreme/boundary Data
a number less than 50. (X <50). If a program asks a user to
A Valid Test data would be 7 (Or enter a number greater than
40 but less than 50. (X> 40
any number between 0 and 49).
and X < 50)
In this scenario the numbers
Example of Invalid Data
41 and 49 are the boundary
If a program asks a user to enter numbers that should be
a number less than 50. (X < 50) accepted by the program
An Invalid Test data would be 55 numbers 40 and 50 are the
boundary numbers that
(Or any number greater than 50)
should be rejected.
Another Invalid test data would
be string like "Apple" as it is not
a number and should be
rejected.

Trace Tables
• When testing more complex examples of software, it is sometimes
necessary to test a number of conditions and sub-conditions at the
same time.
• For this a trace table can be used to record the outcomes of the test.

204
• Here is an example of a very simple trace table, which checks that X =
Y + 4:
Y X
7 11
20 24
Trace Tables
• Here we have a question from the exam to explain how a trace table
can be used.
• In this case we can input number data into this flowchart to establish
how it would be processed and then outputted.
• We will use the following test data:
1.8, 2.0, 1.0, 1.3, 1.0, 2, 5, 2.0, 1.3, 1.8, 1.3, -1

205
Engine Count Number Size Average Output
0 0 0 1.8
1.8 1 1 2.0
3.8 2 2 1.0
4.8 3 1.3
6.1 4 1.0
7.1 5 2.5
9.6 3 6 2.0
11.6 4 7 1.3
12.9 8 1.8
14.7 5 9 1.3
16.0 10 -1
1.6
1.6,5

206
Programming chapter 16
Programming Concepts
• We need to understand and use five basic constructs when
developing a program:
 Data Use - variables, constants and arrays.
 Sequence - order of steps in a task.
 Selection - choosing a path through a program.
 Iteration - repetition of a sequence of steps in a program.
 Operator Use - arithmetic for calculations, logical and Boolean for
decisions.

Variables and Constants


• When you start to write computer programs, you will usually need to
store data while your program is working with it. For example, you may
want to hold values entered by the user so that they can be used in a
computation or to keep a running score while a game is being played.
You will store these values in named variables.
• A variable is a data item whose value can change during the
program's execution. Thus, as its name implies - the value can vary.
Age  35 name  "Mr. Affan (Khalid)",
• We can also use a constant. A constant is used in programming when
a value needs to be available to the program but it will not change
during the execution of the program.
Pi is an example of a constant, it will never change, pi  3.142

207
Declaring Variables and Constants
• It is always considered good practice to
declare the constants and variables to be
used in your computer programs. Some
languages require explicit declarations,
which specifically state what type of
data the variable or constant will hold.
• Other languages require implicit declarations, where the data type is
based on the value assigned. These declarations can be at the start of a
program or just before the data is used for the first time.
• It is always considered good practice to declare the constants and
variables to be used in your computer programs. Some languages
require explicit declarations, which specifically state what type of data
the variable or constant will hold.

Basic data types


• Each variable and constant will be assigned a data type. The data type
determines what type of value the variable will hold.

208
Input and output
• To be able to enter data in a computer program and output the
results, the code need to use both input and output statements.
• For a program to be useful, the user needs to know what they are
expected to input, so each input needs to be accompanied by a prompt
stating the input required. In a programming language the data type of
the input must match the required data type of the variable where the
input data is to be stored.
• All inputs default as strings, so if the input should be an integer or real
number, commands are also used to change the data type of the input
(for instance, in Python. these are int() or float()).

Yourname = input ("Please enter your name: ") Sequence


print ("Hello", yourname) • When designing
Please enter your name: Affan (Khalid) algorithms, it is important
to make sure that all the
Hello Affan (Khalid)
steps are presented in the
correct order. This is known as sequencing, and can be displayed in
pseudo code or flowcharts.
• An incorrect order can lead to incorrect results and/or extra steps
that are not required by the task.

209
Selection
The following is an algorithm for making a cup of tea.
1. Add milk to the cup. • Selection is an
extremely useful
2. Add sugar to the cup.
technique, allowing
3. Boil the water in the kettle. different routes
4. Pour some of the boiled water into the cup. through the steps of
5. Put the teabag in a cup. 6. Drink the tea. a program.

7. Fill the kettle with water. • It is a programming


construct where a
8. Stir the tea.
section of code is run
only if a condition is met.
• In programming, there are occasions when a decision needs to be
made. Selection is the process of making a decision. The result of the
decision determines which path the program will take next.
We can use if and case statements to demonstrate Selection.
IF Temperature > 25 CASE OF Day
THEN 1 OUTPUT "Monday"
OUTPUT "it is too hot!" OUTPUT 2: OUTPUT "Tuesday"
"good temperature" 3 OUTPUT "Wednesday"
ELSE 4 OUTPUT "Thursday"
THEN OUTPUT "it is too hot!" OUTPUT 5 OUTPUT "Friday"
"good temperature"
6 OUTPUT "Saturday"
ENDIF 7: OUTPUT "Sunday"
OTHERWISE OUTPUT "invalid"
ENDCASE

210
Iteration (also known as Looping)
• There will be times when a computer program needs to repeat
certain steps until told otherwise, or until a certain condition has been
met. This process is known as iteration.
• Iteration is often referred to as looping or repetition, since the
program 'loops' back to an earlier line of code.
• Iteration allows programmers to simplify a program and make it more
efficient.
• We can use three different types of loop structure which allow code
to be repeated under certain conditions.
These are:
 Count-controlled loops (for a set number of iterations) (for).
 Pre-condition loops (may have no iterations) (while).
 Post-condition loops (always has at least one iteration) (repeat).
• A programmer can write specific code once, and ask the program to
execute the same line repeatedly until no longer needed.
• FOR loops: are examples of Count-Controlled Loops and are used
when a set number of iterations are required. for count in range (6):
(The code here will print we love codding 6 times, 0 print("We love Coding")
to 5)

• WHILE loops: When the number of iterations is not known, there are
two options.
• Pre-condition loops which may have no iterations post-condition
loops which always.
• Count-controlled loops have at least one iteration.

211
secret_keyword "python" (This code will
continue coming until
user_input input("Please enter the secret keyword: ") the user will enter
while user_input != secret_keyword: the correct
secret_keyword).
user_input input("Please enter the secret keyword: ")

Counting and Totaling


• Counting in the process of keeping a running count of how many
times something happens in a program. It can keep track of how many
iterations your program has performed in a loop.
• Whereas Totaling is the process of keeping a running total of values in
a program. It can be used to sum a list of numbers.
• Both are usually done by changing a variable. They are used when
adding up the marks for a quiz for example.
• Counter  Counter + 1

Counting in pseudo code


1. mynumber = 0
2. WHILE number <= 10 DO
3. OUTPUT mu number
4. mynumber = mynumber + 1

mynumber 0
while mynumber <= 10:
print (mynumber)
mynumber mynumber+1
for newnumber in range(5, 0, -1):
print (newnumber

212
Totaling pseudo code:
1. total 0
2. mynumber = 0
2. FOR x = 0 to 10
3. OUTPUT "Please enter a number" total total + mynumber
4. mynumber INPUT
5. total total + mynumber
6. END FOR
7. OUTPUT "Your total is: " + total
total 0 mynumber 0
mynumber 0
String
for x in range (5):
handling
mynumber = int(input("Please enter a number: "))
• String
total total + mynumber handling is an
print ("Your total is: ", total) important part
of
programming. String variables are used to store text. These strings
contain a number of characters, from art empty string, which has no
characters stored, to a maximum number specified by the
programming language.
Here are some methods you will need to learn when writing algorithms
and programs:
 Length - finding the number of characters in the string.
 Substring - extracting part of a string.
 Upper - converting all the letters in a string to uppercase.
 Lower - converting all the letters in a string to lowercase.

213
#Testing len() Output would be:
String1 = “my name is Affan” The length of the string is 16.
Print (“the length of the string is:”, len(String1))
#Testing substring() Output would be:
String1 = “my name is Affan” My name
Print (String1[:7])
#Testing .upper and .lower Output would be:
String1 = “my name is Affan” MY NAME IS AFFAN
Print (String1 .upper()) my name is affan
Print (String1 .lower())

Arithmetic, Logical & Boolean Operators


Arithmetic Operators:
All programming languages use arithmetic operators to perform
calculations. These are the ones you will need for now.
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
^ Exponent (Raise to the power of)
MOD Modulus (Remainder from Division)
DIV Integer Division
Activity. Using Python write and test a short program to perform these
mathematical operations and output the results:
 Input two numbers, Number1 and Number2
 Calculate Number1 + Number2
 Calculate Number1 - Number2

214
 Calculate Number1 * Number2
 Calculate Number1 / Number2
 Calculate Number1 ^ Number2
 Input an integer Number3
 Calculate Number3 (Number1+ Number2)
 Calculate Number3 (Number1 - Number2)
 Calculate (Number1 + Number2) ^ Number3
# Get input from the user # Perform the calculations
Number1= int(input("Enter Number1: ")) addition Number1+ Number2
Number2 = int(input("Enter Number2: ")) subtraction Number1 Number2

# Print the results multiplication Number1 Number2

print(“Number1 + Number2 =”, addition) division Number1 / Number2

print(“Number1 - Number2 =”, subtraction) exponentiation Number1 ** Number2

print(“Number1 * Number2 =”, multiplication) # Get input Number3 from the user
print(“Number1 / Number2 =”, division) Number3 = int(input("Enter Number3: "))
print(“Number1 ^ Number2 =”, exponentiation)

# Perform the calculations


result1= Number3 (Number1 + Number2)
result2= Number3 (Number1 - Number2)
result3 (Number1 + Number2) ** Number3

# Print the results


print("Number3 * (Number1 + Number2) =", result1)
print("Number3 * (Number1 - Number2) =", result2)
print("(Number1 + Number2) ^ Number3 =", result3)

215
Logical Operators:
Programming languages use logical operators to decide which path to
take through a program. Here are the ones you will need:
Operator Description
> Greater than • Assign values  =
< Less than
• Show it is equal to this number  ==
= Equal to
>= Greater than or equal to • Not Equal to  !=
<= Less than or equal to
<> Not equal to
Boolean Operators:
Programming languages use Boolean operators to decide whether an
expression is true or false. Here are the ones you will need:
Operator Description
And Both true
Or Ether true
Not Not true
Activity: Using Python write and test a short program to perform all
these comparisons and output the results.
• Input two numbers, Number1 and Number2
• Compare Number1 and Number2:
 Output with a suitable message if both numbers are not equal.
 Output with a suitable message identifying which number is
largest.
 Output with a suitable message identifying which number is
smallest.
 Output with a suitable message if both numbers are equal.
• Input another number Number3:

216
 Output with a suitable message if all three numbers are not equal.
 Output with a suitable message identifying which number is
largest.
 Output with a suitable message identifying which number is
smallest.
 Output with a suitable message if all numbers are equal.

# Get input from the user # Compare Number1 and Number2


Number1= int(input("Enter Number1: ")) if Number1 == Number2:
Number2 = int(input("Enter Number2: ")) print("Number1 and Number2 are equal")
else:
# Compare Number1 and Number2
print("Number1 and Number2 are not equal")
if Number1 > Number2:
print("Number1 is larger than Number2") # Compare Number1 and Number2

else: if Number1 < Number2:

print("Number2 is larger than Number1") print("Number1 is larger than Number2")


else:
# Get input Number3 from the user
print("Number2 is larger than Number1")
Number3 = int(input("Enter Number3: "))
# Compare all three numbers
if Number1 == Number2 == Number3:
print("All three numbers are equal")
else:
print("All three numbers are not equal")

217
# Compare all three numbers
if Number1 > Number2 and Number1 > Number3:
print("Number1 is the largest")
elif Number2 > Number1 and Number2 > Number3:
print("Number2 is the largest")
else:
print("Number3 is the largest")

# Compare all three numbers


if Number1 < Number2 and Number1 < Number3:
print("Number1 is the smallest")
elif Number2 < Number1 and Number2 < Number3:
print("Number2 is the smallest ")
else:
print("Number3 is the smallest ")

Display would be like this


Enter Number1: 34 Enter Number1: 55
Enter Number2: 34 Enter Number2: 66
Number1 and Number2 are equal Number1 and Number2 are not equal
Enter Numbe3: 34 Number2 is larger than Number1
All three numbers are equal Enter Number3: 77
All three numbers are not equal
Number3 is the largest
Number1 is the smallest

218
Using Nested Statements
• Selection (IF and CASE) and iteration statements (FOR and WHILE
Loops) can be nested one inside the other.
• This reduces the amount of code that is needed and makes it simpler
for a programmer to test their programs.
if(condition):
#Statements to execute if condition is true
if(condition):
#Statements to execute if condition is true
#end of nested if
#end of if
• In Python programming language there are two types of loops which
are the (for loop) and (while loop). Using these loops we can create
nested loops in Python.
• Nested loops mean loops inside a loop. For example, (while loop)
inside the (for loop), (for loop) inside the (for loop), etc.

Example 1 of multiplication table using nested loops

219
• In this example we have used nested loops to build a times table
generator using only 4 lines of python code.
#set an initial loop with 2 items
#print 1st item in the first loop
#move on to the next loop which has a range from 10, 13
#print each of these items #repeat this because there are 2 items in the 1st loop

for i in range(2):
print (i)
for j in range(10,13):
print (j)

# Running outer loop from 2 to 6

for timestable in range(2, 6): Tables from 2 to 5

# Printing inside the outer loop


# Running inner loop from 1 to 10
Multiply with number
for multipliedby in range(1, 11):
1 to number 10

# Printing inside the inner loop


print(timestable, "*", multipliedby, "=", timestable multipliedby)
# Printing inside the outer loop
print()

Example 2 of lists and nested loops

220
• In this example we have nested a WHILE loop within a FOR loop; this
allows both the lists in the example to be combined together
list1 = ['I am', 'We are']
list2 = ['going to the gym', 'eating dinner', 'wearing sunglasses']

list2_size = len(list2)

for item in lists:


print("...start outer for loop ")
count = 0
while(count < list2_size):
print(item, list2[count])
count = count + 1
print("...end for loop ")
print("")

Display would be like


...start outer for loop ...start outer for loop
I am going to the gym We are going to the gym
I am eating dinner We are eating dinner
I am wearing sunglasses We are wearing sunglasses
...end for loop ...end for loop

221
Procedures and functions
• When writing an algorithm, it is common to encounter multiple tasks
that involve the execution of the same set of statements.
• To avoid repeating the same code multiple times and to make the
code more organized and efficient, programming languages provide the
concept of subroutines, also known as procedures or functions.
• These are blocks of code that are defined only once and can be
reused throughout the program by calling them by their assigned name.
By using procedures and functions, the code becomes more readable,
maintainable and less error-prone.

Procedures, functions and parameters


• Procedures and functions are both groups of programming
statements that can be called by a specific name to perform a certain
task. The main difference between the two is that a procedure does not
return a value, while a function does.
• A parameter is a variable that stores the value of an argument passed
to a procedure or function. Not all procedures and functions require
parameters, but those that do will have specific parameters that must
be included in the call to the procedure or function in order for it to
work correctly.

Defining procedures and functions in our code


• In this pseudo code example we sandwich our program inside a
procedure. We give this procedure a name, insert the code and end the
procedure.
• We can call and use this procedure many times throughout out
program.

222
In Python it would look something like this:
def starbanner():
print("*****************")
print("*****************")
print("*****************")
print('\n' * 3)

def starbanner2():
for i in range(3):
print("*****************")
print('\n')
starbanner()
starbanner2()

• [starbanner()] will print three lines of (*****************) and then


it will leave three lines empty.
• And [starbanner2()] will print one line of (*****************) then
leave one line empty three times.

Functions
• A function is basically the same as a procedure and acts as a set of
instructions or a recipe that you can use over and over again in a
computer program. The difference is, it always returns a value.
• It's defined just once but can be used many times.
• Some languages call them different names, like in Python they are
called "fruitful functions."

223
• Also, unlike other instructions, the output of a function can be used in
other parts of the program.
Function for calculator.

Defining procedures and functions in our code


• The keyword RETURN is used as one of the statements in a function
to specify the value to be returned. This is usually the last statement in
the function definition.

224
• For example, here is a function written in pseudo code to convert a
temperature from Fahrenheit to Celsius:
• Because a function returns a value, it can be called by assigning the
return value directly into a variable.

Local and Global Variables


• A global variable can be used by any part of a program- its scope
covers the whole program.
• A local variable can only be used by the part of the program it has
been declared in-its scope is restricted to that part of the program.

• For example, in this algorithm the variable x is declared both locally


and globally, whereas y is only declared locally.

Library Routines
• When you write code for a computer, you can use pre-written pieces
of code called "library routines."
• These are like tools in a toolbox that you can use to make your
program do different things.

225
• Each programming language has its own set of tools, like string
handling or finding remainders or round numbers. To use these tools,
you have to tell the computer which tool you want to use by writing a
special line of code at the beginning of your program.
• For example, in Java, you might write "import java.lang.String" to use
the string handling tool. When you learn computer science, you will use
these library routines in your programs.
• You will need to use these library routines in your programs for now:
 MOD: - returns remainder of a division.
 DIV: - returns the quotient (i.e. the whole number part) of a
division.
 ROUND: - returns a value rounded to a given number of decimal
places.
 RANDOM: - returns a random number.
# Get two numbers from the user
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
# Divide the numbers and find the quotient and the remainder
quotient = num1 // num2
remainder = num1 % num2
# Print the results
print("Quotient:", quotient)
print("Remainder:", remainder)

226
Import Random
• To generate random numbers in python, we have the random
module/library which needs to be imported.
• The random() function allows us to generate random numbers
between 0 and 1 (generates floating-point random numbers).
• It is a default random generator function.
# Import the random module
import random
# Generate a random number between 1 and 100
secret_number = random.randint(1, 100)
# Ask the user to guess the number
guess = int(input("Guess the secret number between 1 and 100: "))
# Keep asking the user to guess the number until they get it right
while guess != secret_number:
if guess < secret_number:
print("Too Low! Guess again.")
else:
print("Too high! Guess again.")
guess = int(input("Guess the secret number between 1 and 100: "))
# Congratulations message
print("You got it! The secret number was", secret_number)

227
Output would look like
Guess the secret number between 1 and 100: 56
Too low! Guess again.
Guess the secret number between 1 and 100: 78
Too low! Guess again.
Guess the secret number between 1 and 100: 89
Too low! Guess again.
Guess the secret number between 1 and 100: 99
Too high! Guess again.
Guess the secret number between 1 and 100: 93
Too low! Guess again.
Guess the secret number between 1 and 100: 94
Too low! Guess again.
Guess the secret number between 1 and 100: 95
You got it! The secret number was 95

Creating a maintainable program


• Imagine you made a recipe for cookies, but you don't write down the
steps or the ingredients. A few years later, you want to make those
cookies again, but you don't remember exactly how you did it. This is
kind of like what happens when a programmer writes a program, but
doesn't write down how it works. (That’s why we should write
comments and documentation.)
• If someone else wants to update or change the program later on, or if
the original programmer wants to work on it again after a long time,
they may have a hard time figuring out what the program does and

228
how it works. That's why it's important for programmers to write
documentation and comments, so that others (or even themselves in
the future) can understand the program better.
• A maintainable program should:
 Variables
 Constants
 Arrays
 Procedures
 Functions
• be divided into modules for each task using:
 Procedures
 Functions
• be fully commented using your programming language's commenting
feature.

Arrays - One & Two Dimensional


• An array is sort of like a big box where you can store a lot of similar
things.
• Each thing you put in the box has a special number called its "INDEX".
You can use the same name to find all the things in the box, and you
can also find each thing separately by using its index number.
• For example, you can have a list of names and you can order them in
alphabetical order or you can have a list of temperatures and find a
certain temperature by searching.
• The first thing in the box is either number 0 or 1, but most of the time
it is number 0. An array can be one big box or many boxes stacked on
top of each other.

229
One Dimensional Array
• A one-dimensional array can be referred to as a list.
• Here is an example of a list with 10 elements in it where the first
element has an index of zero.
MyList
First Element 0 Zebra
1 Kangaroo
2 Tiger
3 Lion
4 Panda
5 Giraffe
6 Gorilla
7 Elephant
8 Monkey
Last Element 9 Hippopotamus

• Each position in the array can be populated in an array by defining the


value at each index position.
• For instance, we have added "Zebra" to the 0 position in the array
MyList (print(MyList[0])).

Two Dimensional Arrays


• A two-dimensional array can be referred to as a TABLE, like a
database, with rows and columns.

230
• Here is an example of a table with 10 rows and 3 columns, which
contains 30 elements. The first element is located at position 0, 0 (row,
column).

0 1 2
0 1 2 3
1 2 4 6
2 3 6 9
First Element 3 4 8 12
4 5 10 15
5 6 12 18
6 7 14 21 Last Element
7 8 16 14
8 9 18 27
9 10 20 30
• Here in this ↕ direction (horizontal) there are columns and in this ↔
direction (vertical) there are rows.
• When a two-dimensional array is declared in. pseudo code the
following are included.
 The first index value for rows.
 The last index value for rows.
 The first index value for columns.
 The last index value for columns.
 And the data type.

Adding, Deleting, Appending & Sorting in arrays


• On next page is an example of Python code to perform various
operations on a list, where the list represents a shopping basket:

231
#Initializing the shopping basket
shopping basket ["apple", "banana", "cherry", "orange"]
#Adding an item to the shopping basket
shopping_basket.append("kiwi")
print("After adding an item: ", shopping basket)
#Deleting an item from the shopping basket
shopping_basket.remove("banana")
print("After deleting an item: ", shopping basket)
#Appending multiple items to the shopping basket
new items ["grapes", "pear"]
shopping basket.extend(new items)
print("After appending multiple items: ", shopping_basket)
#Reordering items in the shopping basket
shopping basket.sort()
print("After reordering items: ", shopping_basket)

• Output of the following codes would look like:


After adding an item:
['apple', 'banana', 'cherry', 'orange', 'kiwi']
After deleting an item:
['apple', 'cherry', 'orange', 'kiwi']
After appending multiple items:
['apple', 'cherry', 'orange', 'kiwi', 'grapes', 'pear']
After reordering items:
['apple', 'cherry', 'grapes', 'kiwi', 'orange', 'pear']

232
• By writing (.append), we can add one item.
• By writing (.remove), we can remove an item.
• By writing (.extend), we can add multiple (more than one) items.
• By writing (.sort), we can sort it out in an alphabetic order.

Dictionaries and Tuples


• A dictionary in Python is like a special array where you can store
information. Instead of using numbers to find things in an array (list),
you use special names called keys.
• For example, let's say you want to store information about a person.
You could use their name as the key and store their age and address as
the values.

person = {'name': 'Affan Khalid', 'age': '30', 'address': '123 Main St'}
# Accessing values
print(person['name']) # Output: Affan Khalid
print(person['age']) # Output: 30
print(person['address']) # Output: 123 Main St
# Updating values
person['age'] = 31
print(person['age']) # Output: 31
# Adding key-value pairs
person['phone'] = '555-555-5555'
print(person['phone"]) # Output: 555-555-5555
# printing the whole dictionary
print (person)

233
• A tuple in Python can be used to store an array of items that don't
change, like the days of the week.
days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Sunday")
# Accessing values
print(days[0]) # Output: Monday
print(days [2]) # Output: Wednesday
# This will cause an error:
days [0] = "Funday"

• As you can see, you can access the values in the tuple just like you
would with a list(array). But, you can't change the values in a tuple once
you've created it. This makes a tuple a good choice when you want to
store a list of items that won't change, like the days of the week.

File Handling
• In programming, data that will be required again can be stored in a
file using file handling methods. This is because any data stored in
Random Access Memory (RAM) is volatile and will be lost when the
computer is switched off. However, when data is saved to a file, it is
stored permanently and can be accessed at a later time by the same
program or another program.
• The ability to store data in a file and access it later makes file handling
a fundamental feature of programming. Furthermore, data stored in a
file can be shared with other computers, making it a widely used
method for data exchange.

234
• Overall, the importance of file handling in programming lies in its
ability to enable the permanent storage and easy access of data, even
after the program or computer has been shut down.

File Handling in Python


• File handling is an integral part of programming. File handling refers
to the process of creating, reading, writing, and manipulating files.
• In a higher level programming language such as Python, file handling
is simplified with built-in methods that allow the programmer to
interact with files seamlessly.
① Open a file:
• To open a file, we use the open() function in Python. The open()
function takes two arguments the file name and the mode in which we
want to open the file (e.g. read, write, append, etc.

file = open("example.txt", "w") This will create a new file called


example.txt in write mode.
② Write to the file:
• Once we have opened the file, we can write some information to it
using the write() function.
file = open("example.txt", "w") This will write the string "Hello,
world!" to the file.
file.write("Hello, world!")

③ Close the file:

235
• After we are done writing to the file, we need to close it using the
close() function.
file = open("example.txt", "w") This will close the file and ensure
that any changes we made to it are
file.write("Hello, world!")
saved.
file.close()

• In addition to writing to a file, Python also allows us to read from and


append to files using the read() and append() functions respectively.

236
Database chapter 17
Single-Table Databases
• A database is a structured collection of data. It allows people to
organize extract specific information in a way that meets their needs.
The data can include text, numbers, pictures; anything that can be
stored in a computer.
• We also use Relational Databases where two or more tables are
linked together. We will be only studying single-table databases right
now.
• A single-table database contains only one table of information.
Example is:
Country National Military Number Nuclear Atomic Muslim
Language power of weapons power or not
(ranking) soldiers
Pakistan Urdu Rank 7 560000 Many yes Yes
China Chines Rank 3 965000 Not so Yes No
(largest) many
Saudi Arabic Rank 22 480000 Less No Yes
Arab
Turkey Turkic Rank 11 775000 Not so No yes
less

(This information is just for now, so if you might use this book after few years
later then you might feel that this is information is slightly wrong or in accurate
because no one knows when the situation would change.)

237
Uses of databases
• Because they can store lots of information e.g. records of how many
students are registered in a school or how many different items are
sold in a shop.
• Data is usually collected through a form on a computer. If any
changes or additions are made it only has to be done once-data is
consistent.
• The same data can be viewed and used by everyone who has access,
only one file is needed.
• Data is only stored once in a database which means no duplication of
information.
• It is basically used in management departments like shop and schools.

Database structure Primary key

A database is organized using a set of key components. These include:


 Entities - each recorded item.
 Attributes - details about the entity.
 Field - columns used to capture attributes.

238
 Record - one row of details about an entity.
 Table - a set of fields and records.
 Primary key - unique number for an entity.

Validation & Verification


 Validation: This is checking that the correct type of data is
entered.
 Verification: This checks that the data is actually the data you
want.
• For example, validation checks that a postcode has been entered in
the correct format (depending on the country, the right combination of
letters and numbers) and verification checks that the postcode being
entered is the correct postcode.
• It is good to do verification checks with two people entering the same
data. A verification check will see if both sets are the same. If there are
differences, the check will bring up an error message and ask for the
data to be re-entered.
• Various checking methods including:
 range checks
 length checks
 type checks
 presence checks
 format checks
 check digits
Were discussed in detail in Algorithm design and problem solving on
page 198 an on.

239
The basic types of data
• There are 6 basic data types that can be assigned to a database.
Syllabus data type Description Access data type
Text/ alphanumeric A number of Short text/long text.
characters.
Character A single character. Short text with a field
size of one.
Boolean One of two values: True/False.
either True or False, 1
or 0, Yes or No.
Integer A Whole Number. A fixed formatted
number with no
decimal places.
Real A Decimal Number. Number formatted as
decimal.
Date/time Date and/or Time. Date/Time.

Primary Key
• Each record within a table contains data about a person, a single
item, or an event, and it is important to be able to uniquely identify it,
especially when you have a very large database and you need to find
something quickly, e.g. a car parts database.

240
• For this reason we add another field to the database that uniquely
identifies the item in the row. This field is called the primary key. This
field must contain data values that are never repeated in the table, e.g.
a unique ID Number.

Terms of Database:
 DATA - information within the database.
 TABLE - a structure in which data is stored.
 FLAT - file database - a single table database.
 RECORD - a collection of data about a single item.
 FIELD - one piece of data.
 PRIMARY KEY - a unique identifier for each record.
 INDEX - a list of values or items.
 QUERY - a method of searching a database.
 RANGE - Start/End.
 PRESENCE- checks if the data is entered in a specific field or not.
 VALIDATION - this is checking that the correct type of data is
entered.
 VERIFICATION - this checks that the data is actually the data you
want.

Structured Query Language (SQL)


• SQL is a type of query language for writing scripts to obtain useful
information from a database.
• We will use some of the SQL statements to extract information from
databases. This will provide a basic understanding of how to obtain and
display only the information required from a database.
• For example, somebody needing to visit a patient would only require
the ward number and the bed number of that patient in order to find

241
where they are in the hospital. Whereas a consultant could need a list
of the names of all the patients that they care for.
SQL Scripts
• An SQL script is a list of SQL commands that perform a given task,
often stored in a file so the script can be reused.
SQL Query Statement Description
Select Fetches specified fields (columns) from a
table; queries always begin with select.
From Identifies the table to use.
Where Includes only records (rows) in a query that
match a given condition.
Order by Sorts the results from a query by a given
column either alphabetically or numerically.
Sum Returns the sum of all the values in a field
(column). Used with select.
Count Counts the number of records (rows) where
the field (column) matches a specified
condition. Used with select.
What is SQL?
• Data base use their own type of programming language.
• This language is known as structured query language or (SQL).
SQL Code to build a Database
CREATE TABLE shopping (id INTEGER PRIMARY KEY, name TEXT,
quantity INTEGER)
Output would look like:
id name quantity

242
Code to insert the values.
INSERT INTO shopping VALUES (1, "Bananas", 4);
INSERT INTO shopping VALUES (2, "Milk", 1);
INSERT INTO shopping VALUES (3, "Chocolate Bars", 2);
INSERT INTO shopping VALUES (4, "Bread", 1);
Now the output would look like:
id name quantity
1 Bananas 4
2 Milk 1
3 Chocolate Bars 2
4 Bread 1
Terms of Structured Query Language (SQL)
 Structured Query Language (SQL) - the standard query language
for writing scripts to obtain useful information from a relational
database.
 SQL scripts - a list of SQL commands that perform a given task,
often stored in a file so the script can be reused.
 SELECT- an SQL command that fetches specified fields (columns)
from a table.
 FROM - an SQL command that identifies the table to use.
 WHERE - an SQL command to include only those records (rows) in
a query that match a given condition.
 ORDER BY - an SQL command that sorts the results from a query
by a given column either alphabetically or numerically.
 SUM - an SQL command that returns the sum of all the values in a
field (column); used with SELECT.
 COUNT- an SQL command that counts the number of records
(rows) in which the field (column) matches a specified condition;
used with SELECT.

243
Memory storage devices chapter 18

Primary Memory
• It is accessible by the Central Processing Unit (CPU) directly.
• It is the main memory in a computer system.
• It is faster than secondary storage.
• Generally, primary memory refers to the RAM of the system.
• Examples include RAM and ROM (solid-state).

Random Access Memory (RAM)


• The RAM holds all the files and applications that are running on the
system including the operating system.
• It can be accessed randomly.
• It is a volatile memory that is wiped off once the computer system is
powered off.

244
 DRAM
• Dynamic RAM (DRAM) chips are made up of numerous capacitors and
transistors.
• A capacitor holds a bit of information (0 or 1).
• A transistor is like a switch; it allows the control circuitry on the chip
to read from or write to a capacitor.
• DRAM needs to be refreshed (capacitors need to be recharged) every
15 microseconds.
• If they aren't, they will lose their charges and their values would be
operating system.

 SRAM
• Unlike DRAM, Static RAM (SRAM) doesn't need to be refreshed.
• Instead of capacitors and transistors, SRAM makes use of flip flops to
hold bits of memory.
• SRAM also provides a faster access speed (typical DRAM access speed
is 60 nanoseconds, while SRAM access speed is 25 nanoseconds). (So
we can say that Static RAM (SRAM) is better than Dynamic RAM
(DRAM).
(Flip-flop is a circuit that maintains a state until directed by input to change the state. A basic
flip-flop can be constructed using four-NAND or four-NOR gates)

Advantages of DRAM Advantages of SRAM


Less expensive to manufacture. Doesn't need to be refreshed.
Consumes less energy. Data access is faster.
Has a higher storage capacity.

245
Read-Only Memory (ROM)
• It is a non-volatile memory and it contains the data even after the
computer is turned off.
• It is a read-only memory and data stores in it permanently.
• It stores the programs for the boot up, BIOS (basic input/output
system) and the operation of peripheral devices.

Application of RAM and ROM


• A toy car has a circuitry which contains RAM and ROM chips.
• ROM chip stores:
 The factory settings.
 The start-up routines.
• RAM chip stores:
 The instructions sent from the controller.

Secondary Storage
• It is a non-volatile memory that is used by the computer to have more
storage space.
• Data in this memory remains as it is even when the system if powered
off.
• The data in it also remain unchanged until it is deleted or modified.
• It is also known as auxiliary or external memory.
• It stores data and programs.
• Examples include Hard Disk Drive (HDD) and Solid-State Drive (SSD).

246
Principles of operation of HDDs hard disk drive

• A typical HDD will have a number of disks (or platters) which can spin
around 7000 times per second. Usually, each platter has two surfaces
to store data.
• A number of read-write heads have access to the surfaces of the
platters. Typically, they can move from the center of a platter to the
edge and back again 50 times a second.
• On the platters, data is stored in sectors and tracks. Each sector has a
fixed number of bytes.
• The real disadvantage of HDDs is latency.
• Since many applications require the read-write heads to look for the
correct sectors to read/write data, a big number of head movements
are required.
• Users may notice this when they see messages such as 'please wait'
or 'not responding'.

Solid-State Drive (SSD)


• A Solid-State Drive (SSD) is a common secondary storage method,
which makes use of controlling the movement of electrons.
• SSDs remove the issue of latency which HDDs have. They have no
moving parts and all data is retrieved at the same rate.

247
• Most SSDs use flash technology.
• This means that data is stored by controlling the movement of
electrons within NAND chips.
• Data is stored as ones and zeros in millions of transistors in each chip.
• This creates non-volatile rewritable memory.
• Some SSDs use Electronically Erasable Programmable Read-Only
Memory (EEPROM) technology.
• This means that data is stored by controlling the movement of
electrons within NOR chips.
• This makes them faster in operation, but more expensive then flash
technology.
• EEPROM technology also allows data to be read or erased bytes at a
time, flash technology only allows data to be read in blocks.

Off-line Storage
• It refers to the storage devices that need to be inserted to the
computer system in order to access, edit or delete the data.
• This type of storage is generally used to transport data files and to
take a backup of important data.
• Examples include removable HDD/SDD, flash drive, CD, Blu-ray, etc.

Types of Storage Devices


1. Solid State Storage (SSS):
• It stores data electronically and does not have any moving parts.
• It is made of silicon chips (a tiny wafer of silicon used to make an
integrated circuit; a microchip.).

248
• It uses less power and produces less heat.
• It can be found in three types i.e. drives, cards, and modules.
• The transfer of data is much faster because of no mechanical parts.
 USB Flash Drives
• It is also known as a pen drive.
• It connects to the computer system using a USB port.
• It comes in many storage sizes and provides an easy way to transport
the data.
 Memory Cards
• Memory cards are the solid-state storage that comes in different sizes
like flash drives.
• However, these cards require a card reader to read its content.
• The most common use of these cards is in digital cameras to store
pictures.

Solid State Hard Drives


• These hard drives don’t have any moving mechanical parts.
• The data is handled using flash memory chips.
• It offers high reliability, uses less power and faster data access.
2. Magnetic Storage
• It is the most common form of storage device that is a mechanical
device that connects to the computer system.
• It uses magnetization patterns to store data in a magnetizable
material.

249
• In these storages, data is accessed using one or several heads.
• The magnetic field is manipulated to store data in the magnetic
storage device.
• Floppy drive is one of the examples of magnetic storage that is no
longer in use in modern computers.

3. Optical Storage Devices


• In these devices, data is stored as patterns of dots or pits.
• Light is used to read this stored data from the device e.g. a laser
beam.
• The light beam bounces off the surface of the medium to read the
data.
• The light reflects differently in the case of a dot and an empty surface.
• The process to mark the surface using the light beam is known as
‘burning’.
 CD ROM
• It stands for Compact Disk – Read Only Memory.
• It is a non-volatile storage device therefore data cannot be modified
or deleted.

250
• It can store up to 800 MB of data.
 DVD ROM
• It stands for Digital Versatile Disk – Read Only Memory.
• These devices can be used in the same way as CD-ROMs, but they can
hold more data.
 Blu-Ray
• It is a high capacity optical disk and can hold up to 50GB of data.
• The double-layer Blu-ray can hold around 100 GB of data.
• It is used in the same way as CD and DVD ROMs but can store very
high-quality HD videos.
• The 'Blu' represents the blue light i.e. used to read the data unlike the
red light used in CD and DVD ROMS.
• Blue light has a shorter wavelength allowing more data to be stored
in a close orientation.
 DVD-RAM

• DVD-RAM is quite different to CDs or DVDs.


• It uses a number of concentric tracks instead of a single spiral track.
This allows simultaneous read and write operations as well as faster
data access.

251
• They also have greater longevity (over 30 years), making them ideal
for archiving data.
Same but more elaborated points as above
CDs/DVDs
• Compact Disks (CDs) and Digital Versatile Disks (DVDs) are examples of optical storage
devices.
• Both CDs and DVDs use a thin layer of metal and light-sensitive organic dye to store data.
• Both also use a single, spiral track which runs from the center to the edge of the disk.
• On the track, data is stored as pits and bumps. A red laser is used to read/write data.
• Both CDs and DVDs can be designated an R (write once) or RW (read and write multiple
times).
• A DVD differs slightly from a CD.
• A DVD can have two layers, which increases its storage capacity.
• The two layers are joined together with a transparent, polycarbonate spacer and a thin
reflector.
• Single-layer DVDs still have a larger storage capacity than CDs, as the pit size and track
width are smaller.
• Also, DVD layers have shorter wavelengths. The shorter the laser wavelength, the greater
the storage capacity.

Same but more elaborated points as above


Blu-ray
• Blu-ray disks are different to the others.
• They use a blue laser to carry out read and write operations. The wavelength of blue light
is shorter than red light.
• Using a blue laser allows the pits and bumps to be smaller, allowing more data to be
stored.
• Blu-rays disks have a single polycarbonate layer, which avoids birefringence.
• Blu-ray disks come with a secure encryption system, which helps prevent piracy and
copyright infringement.

252
Disk Laser color Wavelength of laser
CD Red 780 nm
DVD Red 650 nm
Blu-ray Blue 405 nm

Virtual memory
• Virtual memory is the use of secondary storage as additional primary
memory.
• Virtual memory is used when the computer has no more available
random access memory (RAM).
• There are times when the amount of RAM needed to hold all running
programs and data is greater than the amount of RAM available to the
computer. When this happens, part of the computer's secondary
storage, such as the hard disk, can be used to store data temporarily.
• Virtual memory enables data that is in RAM and not currently being
used to be transferred to the hard disk. This frees up room in RAM for
other programs and data. When the data on the hard disk is needed.
• Using virtual memory makes a
computer run slower, as the processor
has to wait while data is swapped
between hard disk and RAM. As
secondary storage devices have slower
access times than RAM, the computer's
processing performance can be severely
impaired. Processing performance can
be improved by increasing the size of
the RAM, thereby reducing the need for virtual memory.

253
Cloud storage
• Storing data at a remote location online is known as cloud storage.
When files and data are sent to the cloud, they are actually being sent
to a server that is connected to the internet. Files can be uploaded to a
folder system and downloaded as required.
• In recent years, the cloud has also become a term for internet based
software facilities.
• Cloud storage has many advantages:
 Data can easily be accessed from anywhere with an internet
connection.
 The business running the cloud storage service manages backups
and security.
 Additional storage can be added easily without having to invest in
addition hard drive.
• However, cloud storage also has a number of disadvantages
associated with it:
 If you can access your data from anywhere with an internet
connection, then a hacker can potentially do the same.
 If your internet connection fails, then you won’t be able to access
your files.
 You are relying on other people to correctly secure your data and
keep backups.
 You don’t know if employees of the cloud service will have
access to your data.
• A business that is considering using a cloud computing service will
have to think about whether the advantages outweigh the risks. This is

254
a complex decision and will depend on many factors, including the type
of data to be stored in the cloud system.
• Technology is always changing and it is important to think about the
risks involved when using any new technology. This is especially
important when that technology is used to store information that could
be private and confidential. Do the risks outweigh the disadvantages? Is
the technology likely to suffer from some kind of cyber-attack?

255
Operating Systems chapter 19
Operating Systems
• An operating system can be defined as a software program that is
responsible for managing and controlling the operations of the
computer, programs, and hardware.
• It also acts as an interface that allows the user to run an application
using a hardware device.
• Without an operating system, a computer working with a computer
system will be impossible for most users.
• Examples of operating systems include Windows, Linux, Android,
DOS, etc.

Functions of an Operating System


• It provides security to user data by using password protection and
other security techniques.
• It also protects user data from unauthorized access.
• It monitors and controls the system's performance by analyzing
response time i.e. the time between system response and service
request to help troubleshoot performance issues.
• It also performs the job accounting for a particular user or group of
users by tracking the resources and time used.
• It also monitors the system performance to avoid system
malfunctioning.
• It is responsible for assigning software such as compilers, interpreters,
assemblers, etc. to perform various tasks.

256
• It is also responsible for managing the Main Memory by keeping track
of the bytes that are utilized by a program, tracking used and unused
memory addresses.
• The operating system also allocates and deal locates the memory to
processes.
• The operating system also performs process scheduling i.e. in a multi-
programming environment, it controls the order of processes and their
processing time.
• It also controls the communication of devices to their respective
driver by tracking the devices that are connected to the system and
designating the input or output controller.
• It also controls the file system by tracking where user data is stored as
well as manages the user access settings.

Uses of Operating System


 Human computer interface (HCI)
 Multitasking
 Multiprogramming
 Batch processing
 Error handling
 Loading and running of applications or software
 Management of user accounts
 File utilities (e.g. copy, save, sort, delete)
 Processor management
 Memory management
 Real-time processing
 Interrupt handling routines
 Security (manages log on, passwords)
 Input and output control
 Human computer interface (HCI)

257
• When a computer is turned on, the start-up programs located in ROM
are loaded into memory.
• These programs check to make sure things such as the hardware,
processor, internal memory and Basic Input or Output System (BIOS)
are functioning correctly.
• If no errors are found, the operating system is loaded into memory.
• Some devices with microprocessors don't require an operating
system.
• Microprocessors operating devices such as microwaves have only one
function, so there is no need for one.

Need for Interrupts


• An Interrupt can be defined as a signal that is sent by software or
device to the processor.
• When an interrupt is received by a processor; the processor pauses
whatever it was doing and handles the interrupt.
• The interrupt can be received by the processor in many situations,
few examples are given below:
 When a disk drive is ready to receive more data.
 When an error has occurred e.g. printer paper jam.
 When the user wants to break the current process e.g. pressed
keys at the same time.
• When the processor has received the interrupt it either stops the
current process and.

258
Example
• You can download a file from the internet, and watch a movie or play
a game on the system at the same time.
• After an interrupt is initiated and serviced by the processor the
current task's status is changed from 'run' to 'saved'.
• Once the interrupt is serviced completely, the status is reinstated and
the task starts from the point it was left before the interrupt was
serviced.

259
260
(Warning: if you are any kind kafir (non Muslim) or hate of Pakistan, do not dare
to print last two pages as you will not able to respect these respectful pages.
(Do mind, I don’t care))

The end☠💀💪🏻

261

You might also like