0% found this document useful (0 votes)
30 views121 pages

1-Data Representation

Uploaded by

fishei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views121 pages

1-Data Representation

Uploaded by

fishei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 121

Computer Science

Data Representation
Debugging
• I mentioned programmers use
Hexadecimal to debug code instead of
using Binary.

• But what does it actually mean to


“debug”?
Definition (Noun)
• The process of identifying and removing
errors from computer hardware or
software.

• Or used as a verb: To identify and


remove errors from computer hardware
or software.
Question
• Why is it important for a programmer to
be able to effectively debug a computer
program?
Analogue vs Digital data
• What does this mean?
• Before we get into the idea of “analogue
and digital”, lets first discuss…
• What is “Data”?
What’s the difference?
• We have data, information, and
knowledge.
• What does each term actually mean?
What is this?
Example
P952BR
@bbcclick
359

NONSENSE!
A
P952BR
load ofcould
rubbish,
be aitproduct
means nothing
code, a post/ZIP
because code,
it has
a car registrationnonumber,
meaning.a robot, anything.
This is data.
In your books
• Write down a series of data about
yourself.
• No context or meaning.
• Text, numbers, countries, names, etc.
• Once you’re done, show them to your
partner.
Can you guess what my data means?
Data
32
12
Russia
0
2
Ford Mustang
Final Fantasy 7
Fortnite
What is this?
Data Context Comment
P952BR Product code Still data, what product?
@bbcclick Twitter username Whose address?
359 Price in Pakistani Rupees What’s the price for?

Giving context, doesn’t mean it’s not information.


It needs meaning!
In your books
• Your data from earlier, convert it into
information by giving each piece of data
meaning.
• Then show it to your partner again.
• How much data did they guess correctly?
My data -> My information
Data Meaning
32 My age
12 Number of countries visited
Russia Favourite country visited
0 Number of siblings
2 How many old my dog is
Ford Mustang Favourite car
Final Fantasy 7 Favourite game
Fortnite Most hated game
What is this?
Data Context Meaning
P952BR Product code A can of noodles.
@bbcclick Twitter username Twitter address for BBC weekly
technology show
359 Price in Pakistani Rupees Price of a mobile phone cover

Now it has meaning, it becomes information.


We can now use this information, it’s useful.
What is knowledge then?
• This is expanding information based on
what you already know.
• The president of America is Joe Biden.
This is just information.
• How do we turn this into knowledge?
What is knowledge then?
• Joe Biden is 78 years old.
• He has been president since 2021.
• He is 182 CM.
• He is the 46th US president.
• He is part of the Democratic Party.
• Knowledge is information you ALREADY
know and can expand upon.
My information -> Your knowledge
Data Meaning Knowledge
32 My age
12 Number of countries visited
Russia Favourite country visited
0 Number of siblings
2 How old my dog is
Ford Mustang Favourite car
Final Fantasy 7 Favourite game
Fortnite Most hated game
Review
• What is data?
• What is information?
• What is knowledge?
• Which do you think is the most
important? Why?
Back to digital and analogue data
• Analogue data is the “real world” of
senses.
• Everything we see, hear, feel and smell
is a constant series of senses.
• Such as listening to music
Analogue data can flow, digital cannot
Logic gates
• We go into way more detail on logic
gates in the future, but the basic jist is.
• If a gate is open (true), it is 1.
• If a gate is closed (false), it is 0.

• Now, there are different types of gates so


this isn’t always correct. But again,
future chapter.
Logic gates
Text book time!
• Read pages 9-13
• Answer question 1 & 2 on page 10
• And complete questions 1-8 on pages 12
& 13.
Answers Q1 & Q2 (P10)
1. Any examples that are heard, smelt,
seen or touched.
2. It has lots of different possible values,
rather than limited values like discrete
data (Digital).
Skill focus 1.1 answers
1. 15 5. 01111011
2. 0110 6. 255
3. 1001 7. 99
4. 00111010 8. 25225
Back to hexadecimal
• Our favourite! (for now)
• Read pages 14-16 and complete
questions 1-4
• After that, use the computers to
research more uses of hexadecimal
(you’ll have to work in pairs for this)
Answers
1. 10100010
2. 9D1
3. 15E
4. 940
Uses of hexadecimal
• Colour codes
• MAC addresses
• Assembly code
• Memory dumps
• Debugging
• Anything else?
Worksheet 1.1 conversion (again)
Part 1 Part 2
1. 6 1. 0101
2. 0 2. 1010
3. C 3. 1110
4. A 4. 0010 0001
5. B7 5. 0001 0000
6. FD 6. 1010 1011
7. 210 7. 1101 0101
8. BFA 8. 0001 1110 1111
9. F0AF 9. 0010 0000 1011
Convert these binary additions to
denary and work out the answer:
binary 0 + binary 0 = denary 0 =

binary 0 + binary 1 = denary 1 =

binary 1 + binary 0 = denary 1 =

binary 1 + binary 1 = denary 2 =

binary 1 + binary 1 + binary 1 = denary 3 =


Convert these binary additions to
denary and work out the answer:
binary 0 + binary 0 = denary 0 = binary 0

binary 0 + binary 1 = denary 1 = binary 1

binary 1 + binary 0 = denary 1 = binary 1


Now back to binary
binary 1 + binary 1 = denary 2 = binary 10

binary 1 + binary 1 + binary 1 = denary 3 = binary 11


Convert these binary additions to
denary and work out the answer:
binary 0 + binary 0 = denary 0 = binary 0

binary 0 + binary 1 = denary 1 = binary 1

binary 1 + binary 0 = denary 1 = binary 1

binary 1 + binary 1 = denary 2 = binary 10

binary 1 + binary 1 + binary 1 = denary 3 = binary 11


Binary manipulation
• In the exam, you have to be able to add
2 8-bit binary figures together.
• To do this, you need to remember 4
simple rules:
Rules:
1. 0 + 0 = 0
2. 1 + 0 = 1
3. 1 + 1 = 10
4. 1 + 1 + 1 = 11
• Makes sense right?
• It’s more simple than it looks, but make
sure you write them down then I’ll show
you how it works.
Lets look at it together
Leftover 1 1 1 1

0 1 1 0 0 1 1 0 1
+
0 1 0 0 1 1 1 1 0
Result 1 0 1 1 0 1 0 1 1

205 + 158 = 363


Read pages 16-18
• And answer question 3 & 4 (show working)
Write some challenges for your friend
• Give your friend 10 questions.
• 2 8-bit binary numbers to add together.
Logical binary shifts
• This is when the binary is moved left or
right.
• These shifts can happen multiple times.
• For instance, 2 left logical shifts
0 0 1 0
0 1 0 0
1 0 0 0
Logical binary shifts
• Gaps created by the shift at the
beginning or end are filled with 0’s.
0 0 1 0
0 1 0 0
Overflow 1 0 0 0
1 0 0 0 0
• What happens when we shift left again?
Overflows
4 options for an overflow, the exam paper will describe
what happens.
0 0 1 0
0 1 0 0
ERROR
1 ERROR
0 ERROR
0 0
1 0 0 0 0
1
Logical binary shifts
• You might have noticed already, but
what happens to the denary value when
we do a logical left shift?
0 0 1 0 2
0 1 0 0 4
1 0 0 0 8

• It doubles/multiplies by 2 each shift!


Right logical shifts
• Same process but to the right.
1 1 1 1 15
0 1 1 1 7
0 0 1 1 3

• This is dividing by two, but if it’s an odd


number you lose the modular
component (left over).
Logical shifts
• This is a way of very quickly doing maths
using binary.
• Read pages 19-20 and complete
questions 5 and 6.
Answers
• 5) Each bit in the byte is shifted either to
the left or the right by a set number of
places.
The spaces left from the value shifted are
replaced with 0 values.
• 6) 00111011
Negative binary numbers?
• So far, everything has been done using
positive numbers…But how do we
represent a negative number using
binary?
• Signed bit integers
Signed bit integers
• The way we store numbers, we reserve
the furthest most left value as a signed
bit.
• This represents if the number is positive
or negative.
Signed bit integers

0 0 0 0

Signed bit:
Remaining bits
0 = Positive
for storing value
1 = Negative
Signed bit integers

0 0 1 1 =3

1 0 1 1 = -3
Two’s complement
• This can cause issues when it comes to
doing maths in binary.
• So we can use One’s Complement or
Two’s Complement.
• For this course and exam you need to use
Two’s Complement.
• (This is different but very similar to what
we did with addition the other day)
One’s complement is easy
• You just invert the binary

The problem is,


11111111 and 0 1 1
00000000 are
both equal to
zero using Ones
Complement
due to the
signed bit.
1 0 0
One’s complement is easy
• You just invert the binary

000 = 0
111 = -0
0 0 0
So this is why
we now use
Two’s

1 1 1
Complement
Two’s complement

0 0 0 0

Signed bit:
Flip all remaining bits and add 1 for
0 = Positive
storing value
1 = Negative
Range of storable integers

Number Range (signed) Range (unsigned)


of bits [22n – 1] ±[22n-1 – 1]

4 0 through 15 -8 through 7
8 0 through 255 -128 through 127
16 0 through 65,535 -32,768 through 32,767
32 0 through 4.29 billion -2.15 billion through 2.15 billion
Think of it as a second binary language
Denary 4-bit binary
-8 1000
-7 1001
-6 1010
-5 1011
-4 1100
-3 1101
-2 1110
-1 1111
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
The most confusing part about this
• The number of bits you use, affects the
end value.
• In the exam, it will almost always be 8
bit.
• But to give an example…
Bit difference
4 bit 8 bit
Denary 3 Denary 3
Binary 0011 Binary 0000 0011
Complement 1101 Complement 1111 1101

12 bit 16 bit
Denary 3 Denary 3
Binary 0000 0000 0011 Binary 0000 0000 0000 0011
Complement 1111 1111 1101 Complement 1111 1111 1111 1101
Binary
• We know the smallest number we can
represent in binary is 0.
128 64 32 16 8 4 2 1
0 0 0 0 0 0 0 0 =0

• If we add 1, this becomes positive and


increases in value.
128 64 32 16 8 4 2 1
0 0 0 0 0 0 0 1 =1
So how do we do negative numbers?
Two’s complement
Two’s complement
How to think about it
The most left value is now a negative value.

-128 64 32 16 8 4 2 1
0 0 0 0 0 0 0 0

So if we want a positive value of lets say…117


How to think about it
Representing +117

-128 64 32 16 8 4 2 1
0 1 1 1 0 1 0 1
64 32 16 4 1
+117

This is the same as our current binary system we already know…


But what about -117?
How to think about it
Representing -117

-128 64 32 16 8 4 2 1
1 0 0 0 1 0 1 1
-128 8 2 1
-117

So when we do the negative value, we basically count


BACKWARDS from the highest most value.
An easy method
• An easy way to convert from POSITIVE to NEGATIVE
Two’s Complement is simple, following these rules:
1. Write out the positive version of the number (in
binary)
2. Starting from the most right hand digit, copy out
each digit exactly as they appear, up to and
including the first 1 you come across.
3. Swap every 1 for a 0, and every 0 for a 1
afterwards..
An example. +12 to -12
-128 64 32 16 8 4 2 1
0 0 0 0 1 1 0 0
1 1 1 1 0 1 0 0

We copy from the right, all of the values UP TO


AND INCLUDING the first 1.

The next left digit onwards, we invert.


A 2nd method
• That first method is quite wordy, so this
method is a bit easier to understand, but
requires more work.
1. Find the positive value in binary.
2. Invert/flip all of the binary.
3. Add 1 to the end.
Lets look at 8 bit numbers
• Let’s say we want to find -28 in Two’s
complement.
• First we find +28 in binary.
Then we add
0 0 0 1 1 1 0 0 1.
And
• Then we invert the digits. 1 1 remember,
1+1=10
1 1 1 0 0 0
1 1
0 1
0
Lets look at 8 bit numbers
• Let’s say we want to find -56 in Two’s
complement.
• First we find +56 in binary.
Then we add
0 0 1 1 1 0 0 0 1.
And
• Then we invert the digits.
1 1 1 remember,
1+1=10
1 1 0 0 0
1 01 1
0 1
0
Try the worksheet
• Using either method, but show your
working.
• Convert the Two’s Complement.
Answers
1. 1101 0011
2. 1101 1101
3. 1111 0100
4. 1001 1100
5. 1100 0001
6. 1011 0011
7. 1001 1101
8. 1000 0001
9. 1111 1011
10. 1110 1000
7
0110
8
01001
113
00100110
65
01011001
87
01100100
63
01111111
0111 -7
0110 -6
01101 -13
010101 -21
00011011 -27
00110101 -53
01110001 -113
01010110 -86
00101011 -43
01100010 -98
0111111 -127
1000000 -128
0010 1110
0000 1010 1111 0110
01 1000 10 1000
0010 0011 1101 1101
011 1010 100 0110
011 1101 100 0011
0100 1011 1011 0101
0101 1001 101 0011
0110 0100 1001 1100
0111 0100 1000 1100
0111 1100 1000 0100
010000010 101111110
What can we do with these negative numbers?

• Addition and subtraction with binary!


(3 + -3)
Two’s complement
1 1 1
0 0 1 1 =3 1+1 = 10
1+1+0 = 10
1+0+1 = 10
1+0+1 = 10
1 1 0 1 = -3 This final 1 is
an overflow,
so it’s
1
0 0 0 0 =0 deleted.
(5 + -2)
Two’s complement
1
0 1 0 1 =5
1+0 = 1
0+1 = 1
1 1 1 0 = -2 1+1 = 10
1+1 = 10
1 overflow.

1
0 0 1 1 =3
(-5 + 2)
Two’s complement
1

1 0 1 1 = -5
1+0 = 1
1+1 = 10
0 0 1 0 =2 1+0 = 1
1+0 = 1

1 1 0 1 = -3
(-2 + -3)
Two’s complement
1

1 1 1 0 = -2
0+1 = 1
1+0 = 1
1 1 0 1 = -3 1+1 = 10
1+1+1 = 11
1 Overflow
1
1 0 1 1 = -5
Write some challenges for your friend
• Give your friend 10 questions or more.
• Adding two 8 bit two’s complement
numbers together.
• Mix up your questions! Give binary give
denary, make them work!
• One positive and one negative number.
• Two positive numbers together.
• Two negative number together.
Text to binary
• We’ve done this before, but lets review.
• We use a type of binary called…
• ASCII
• Which stands for?
• American Standard Code for Information
Interchange
Unicode
• This is similar to HEX, but whereas Hex
can hold a value of 16 characters.
• Unicode can hold around 65000
• Hello in Unicode:
• \u0048\u0065\u006c\u006c\u006f
• 你好 in Unicode:
• \u4f60\u597d
Solve Practical Activity 1.2
Page 21 128 64 32 16 8 4 2 1
Try writing messages again using this table
128 64 32 16 8 4 2 1
Worksheet 1.3
• Answers:
1. hello computing is fun
Worksheet 1.3
• 1 If each character can Binary Octal Decimal Hexadecimal
0000 0 0 0
have only 4 bits, how many 0001
0010
1
2
1
2
1
2

different characters can 0011


0100
3
4
3
4
3
4

you have? 0101


0110
5
6
5
6
5
6

16 0111
1000
7
10
7
8
7
8
1001 11 9 9
1010 12 10 A
1011 13 11 B
1100 14 12 C
1101 15 13 D
1110 16 14 E
1111 17 15 F
Worksheet 1.3
• 2 If each character can have 8 bits, how many different
characters can you have?
256
• 3 Create a set of codes that use 8 bits for capital letters and
numbers.
You cannot use the same code twice, and you cannot use any of
the numbers used in the code at
the start of this worksheet.
E.g. Use 30-56 for capitals (e.g. A = a +20) and 100 to 109 for
Converting images to binary
• Images are made up of pixels. What are they?
• Tiny squares, which can be given a colour value, and
when combined make a picture.
• Pixel means:
PICture
ELement
Binary
• We can also use binary to create images.
Obviously that’s just black and white
• We can add more colours, but what issue could that cause?
• More memory usage.
• If we’re storing 1 bit of data per pixel for a 256 pixel image.
That is: (1x256)/8 = 32Bytes
• If we add 8 bits of colour data per pixel, that same 256
image becomes: (8x256)/8 = 256Bytes
• If we add 64 bits of colour data per pixel, that same 256
image becomes: (64x256)/8 = 2048Bytes (2KB)
The amount of colour available
scales exponentially
Easier to see why with grayscale
We often use Hex for colours
Basic colours
Color HTML / CSS Name Hex Code#RRGGBB Decimal Code(R,G,B)

Black #000000 (0,0,0) Color vs colour.


White
Red
#FFFFFF
#FF0000
(255,255,255)
(255,0,0)
When it comes to adding
Lime
Blue
#00FF00
#0000FF
(0,255,0)
(0,0,255)
colours to your programs later
Yellow
Cyan / Aqua
#FFFF00
#00FFFF
(255,255,0)
(0,255,255)
on, it’s all American spelling.
Magenta / Fuchsia
Silver
#FF00FF
#C0C0C0
(255,0,255)
(192,192,192)
If you type colour it wont
Gray
Maroon
#808080
#800000
(128,128,128)
(128,0,0)
understand it.
Olive #808000 (128,128,0)
Green #008000 (0,128,0)
Purple #800080 (128,0,128)
Teal #008080 (0,128,128)
Navy #000080 (0,0,128)
https://www.rapidtables.com/web/color/RGB
_Color.html
Homework Worksheet
• Draw some pictures and do the binary.
• Please note that the binary values for
each colour in this worksheet are NOT
correct, it’s just to visualise the system.
• So you can assign colours to binary
values on this worksheet.
Metadata
• Inside each picture is additional data
known as metadata.
• What kind of data do you think is in this?
Metadata
• Your location
• Your phone or camera type
• Names, and numbers
• Dimensions
• Image ratio
• Colour depth
• etc
Metadata
• This data not only increases file size, but
it can also be uploaded to social media
sites and other people can access that
data.
• Didn’t you ever wonder how Instagram,
etc knew where you took the picture?
Metadata
Metadata
Metadata
Read pages 21-23
• Take notes of what we’ve just looked at
regarding pictures and metadata.
Analogue to Digital sound
• How to convert analogue to digital audio

• How the number of bits affects the qualit


y of the sound

• Read page 23-25 (up to 1.4)


Measuring data storage
• What storage units do we know? • W
• Bit • Bit
• Nibble • Nibble
• Byte • Byte
• Kibibyte • Kilobyte
Also known as
• Mebibyte • Megabyte
• Gibibyte • Gigabyte
• Tebibyte • Terabyte
• Pebibyte • Petabyte
• Exbibyte • Exabyte
Measuring data storage
Unit Description Example

Bit 1 or 0 A single pixel in a black and white picture

Nibble 4 bits As easier way of debugging


Byte 8 bits A single character

Kilobyte 1024 bytes A small email is about 2 kilobytes

Megabyte 1024 kilobytes MP3 files take up about 1 megabyte per minute

Gigabyte 1024 megabytes 1 gigabyte can hold about 300 MP3 songs

Terabyte 1024 gigabytes 1 terabyte can hold about 100 DVD-quality films

1 petabyte can hold enough MP3 songs to play continuously for


Petabyte 1024 terabytes
over 2000 years - without repeating!

Some technologists have estimated that all the words ever


Exabyte 1024 Petabytes
spoken by mankind would be equal to five Exabytes.
Measuring data storage
• It can be difficult to understand the shee
r size of this data storage, so here’s a fun
video to show the scale of it all.
How to calculate data storage of an
image.
• (Image height x Image width) = Number of pixels
• Number of pixels x Colour depth = Number of bits.
• Number of bits / 8 = Number of bytes
• From the bytes, you divide by 1024 a number of times to
reach your target file size.
• For instance if you wanted to reach TiB you’d divide by
1024 4 times.
How to calculate data storage of an
image.
• Say we have an image, 150x250 resolution at 16bit colour
depth. And I want to calculate the MiB size.
• This equals 37 500 pixels.
• Then we do 37 500 x 16 = 600 000 (number of bits).
• Then we do 600 000 / 8 = 75 000 (number of bytes)
• Now I need to find the MiB from these bytes.
• 75 000 / 1024 = 73.24 (KiB)
• 73.24 / 1024 = 0.07 (MiB)
How to calculate data storage of an
audio file.
• (Sample rate x Sample resolution) x Length of soundtrack.
• This gives you the bits.
• Then same as an image. Divide bits by 8 for the bytes.
• Then divide by 1024 the number of times required for your
designated file size.
How to calculate data storage of an
audio file.
• Lets say our audio is:
• 15 seconds long.
• Sample rate of 44,100 HZ
• Sample resolution of 16 bits. And I want the MiB size.
• We do rate x resolution first, then x by length.
• 44,100 x 16 = 705,600 (bits per second)
• 705,600 x 15 = 10,584,000 (total bits in the file)
• 10,584,000 / 8 = 1,323,000 (total bytes in the file)
• 1,323,000/1024 = 1,291 KiB.
Measuring data storage

• In the exam, you don’t have to divide by


1024. In the exam you can divide by
1000... Sometimes.
For the new syllabus (first examined in 2023)
when candidates are asked to perform calculations
or conversions as part of their answer?
• Candidates should be taught to use the division/multiplier
of 1000 and 1024 at the appropriate time for the IGCSE
Computer Science syllabuses.
• Candidates will be told which suffix to use, for example an
answer must be in KB or KiB. If they are told KiB then they
will need to use 1024. If they are told KB then they will
need to use 1000.
Measuring data storage
• Basically, if it’s in ibibytes (KiB, MiB, GiB,
etc) then you divide by 1024.
• If it’s a normal byte value (KB, MB, GB,
etc) then you divide by 1000.
Measuring data storage
• Read pages 25-27
• Take notes.
Answers
• Q1) 3 times
• Q2) 1 500 000
Data compression
• What is this?
• .zip .rar .7z
• This is when we make a file size smaller.
• There are two ways of doing this:
Lossy and Lossless.
What do you think these two terms
mean?
Lossy compression
• As the name suggests, data is lost to
make a file smaller.
• This is often seen in streaming services
such as YouTube, etc. It’s 1080P, but the
streamed video is not the same quality
as the original 1080p video which is not
compressed.
Lossless compression
• The opposite, of lossy.
• Data is kept 100% but made smaller.
• How it works
Task
• Have a read pages 27-29 and answer
questions 7-9 on page 27
Answers
7. It could potentially remove data that is vital.
All text in a file is likely to be required, so
none can be removed.
8. Yes, as it will remove some of the detail, such
as reducing the number of colours used to
create the image.
9. Yes, as it will remove some of the natural
background noises, etc. from the recording,
so it won’t be as close to the original
Homework task
• On ManageBac, I have set a task for you
due on Monday.
• It must be submitted digitally.
Review before exam!
• On Thursday you’ll have your first taste
of a Computer Science theory exam!
• It’ll be closed-book, so try and use this
time to prepare.

• I was going to do it on Friday…But covid


tests…

You might also like