Topic-7c-Data-Representation

advertisement
Computing Science
National 4 & National 5
Unit 1
Information Systems Design & Development
Topic 7c
Data Representation
N4/ N5 Computing Science
Data Representation
Contents
Contents................................................................................................................... 2
Introduction ............................................................................................................. 3
Advantages of Using Binary ..................................................................................... 3
Representing Characters (Text) ............................................................................... 4
ASCII ............................................................................................................. 4
Control characters ....................................................................................... 4
Unicode ........................................................................................................ 4
Representing Numbers ............................................................................................ 6
Units of Storage ........................................................................................... 6
Representing Positive Numbers .................................................................. 6
Representing Large (Real) Numbers ............................................................ 8
Representing Graphics............................................................................................. 9
Representing Black & White Bitmapped Graphics ...................................... 9
Resolution .................................................................................................... 9
Calculating the Size of a Black and White Bitmapped Graphic ................. 10
Colour Depth.............................................................................................. 10
Calculating the Size of a Colour Bitmapped Graphic ................................. 11
Vector Graphics ......................................................................................... 11
Trinity High School
Page 2
N4/ N5 Computing Science
Data Representation
Introduction
Computers are used to store a variety of information including numbers, text, graphics
and even sound. Regardless of the type of information represented, it is all stored as bit
patterns made up from the digits 1 or 0. In other words everything that is stored on the
computer is eventually broken down into its simplest form, which is a pattern of 1s and
0s. This is called binary or machine code.
Advantages of Using Binary
Binary might seem a little confusing, but in fact it is very simple system which is ideal for
computers. But why is this?



Binary is a simple two-state system (1 or 0) which is ideal when representing a
two state system of power on/power off
There are only a few rules for addition, making calculations simpler (compared
to decimal).
A degraded signal can still be detected as representing 1 or 0.
e.g.
Degraded Signal…
Trinity High School
can be still be read as…
Page 3
N4/ N5 Computing Science
Data Representation
Representing Characters (Text)
When you are using a program and you press a key on the keyboard the program has to
have some way of identifying which key you pressed. This is true for any program
whether it is a word processing package, spreadsheet or game. Each character on the
keyboard has a unique binary code allocated to it. The group of letters, numbers and
characters that the computer can work with is called the character set.
ASCII
One example of a character set is ASCII. It stands for American Standard Code for
Information Interchange.
ASCII code includes:




Non-printing characters: <return>, <tab> (see below)
Numbers: 0-9
Upper and Lower Case Letters: A-Z, a-z
Punctuation and other symbols: $, %, !, ?, @
Control characters
Most ASCII characters are either displayed on the screen or can be printed on a printer
but there are some that serve a different purpose. Control characters include keys such
as RETURN, TAB and DELETE. They are the first 32 characters in ASCII. These are used to
send a control signal to a printer e.g. BACKSPACE or NEW LINE. Sometimes control
characters are referred to as ‘non-printable characters’.
Unicode
With an increase in worldwide communication and the need to represent different
languages symbols a 16 bit character code (65, 536 symbols) called Unicode is used.
This represents foreign languages such as Japanese or Arabic.
Trinity High School
Page 4
N4/ N5 Computing Science
Data Representation
Activity
ASCII Code: Character to Binary
0
0011 0000
L
0100 1100
1
0011 0001
M
0100 1101
2
0011 0010
N
0100 1110
3
0011 0011
O
0100 1111
4
0011 0100
P
0101 0000
5
0011 0101
Q
0101 0001
6
0011 0110
R
0101 0010
7
0011 0111
S
0101 0011
8
0011 0111
T
0101 0100
9
0011 1001
U
0101 0101
A
0100 0001
V
0101 0110
B
0100 0010
W 0101 0111
C
0100 0011
X
0101 1000
D
0100 0100
Y
0101 1001
E
0100 0101
Z
0101 1010
F
0100 0110
.
0010 1110
G
0100 0111
,
0010 0111
H
0100 1000
?
0011 1111
I
0100 1001
!
0010 0001
J
0100 1010
(
0010 1000
K
0100 1011
)
0010 1001
S
P
A
C
E
0010 0000
Trinity High School
1. What does ASCII stand for?
2. What is ASCII used to represent?
3. What is a non-printable character?
4. What is a character set?
5. Use the table to the left to write out
your name in ASCII
6. Write a secret message in ASCII in
your jotter and swap with the person
on your right and try to decrypt it.
7. What is Unicode?
Page 5
N4/ N5 Computing Science
Data Representation
Representing Numbers
Units of Storage
Bit is short for binary digit and is the smallest unit of measurement on a computer
having either the value 0 or 1. Memory is measured by the byte, and a byte can store a
single character. An example of this is that the word ‘egg’ is three characters long and
therefore requires 3 bytes of computer memory storage. Modern PCs require billions of
bytes to simply load up the operating system, so to make these huge quantities of bytes
easier to refer to, there are a number of terms to describe them.
Bit = 0 or 1
Byte = 8 bits
Kilobyte = 1024 bytes
Megabyte = 1024 KB
Gigabyte = 1024 MB
Terabyte = 1024 GB
Petabyte = 1024 TB
Representing Positive Numbers
Decimal Number System
Humans use the decimal number system to count, which involves the digits: 0 to 9. For
example the number 2347 is made up like this:
1000
2
100
3
10
4
1
7
- These are the place values
- These are the digits
This means 2x1000 + 3x100 + 4x10 + 7x1 = 2347. Because we are so familiar with this
process we don’t think about it when using decimals, but it is useful to remember this
method to help us understand how the binary system works.
Binary Number System
Computers use the binary number system to count which only involves the digits: 0 & 1.
The place values in binary go up in twos, so instead of having place values of units, tens,
hundreds, etc, it has units, twos, fours, eights, etc… For example:
8
1
4
1
2
0
1
1
- These are the place values
- These are the digits
Therefore the binary number 1101 is represented as 1x8 + 1x4 + 0x2 + 1x1, which is
equal to the value 13 in decimal.
Trinity High School
Page 6
N4/ N5 Computing Science
Data Representation
A computer stores data in its memory in bytes - which is made up of 8 bits. The
maximum value that any one bit can be is 1, therefore the maximum value that can be
represented by a byte is:
128
1
64
1
32
1
16
1
8
1
4
1
2
1
1
1
This value can be converted to decimal: 128+ 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255. Of
course, a byte can also have the value zero (00000000). So a byte can hold a range of
values from zero (00000000) to 255 (11111111), making a total of 256 different
numbers.
Activity
1.
1 terabyte is the same as:
A
B
C
D
2.
The number 23 represented in binary is:
A
B
C
D
3.
10111000
00000111
00010111
11101000
The binary number 00101001 is what in decimal?
A
B
C
D
4.
1024 gigabytes
1024 megabytes
1000 megabytes
1024 bytes
82
41
148
255
Convert the following binary numbers into decimal values.
a) 00100010
b) 10000011
c) 01111111
5.
Convert the following decimal values into binary numbers.
a) 97
b) 135
c) 223
6.
Practice your binary  decimal conversion at:
http://forums.cisco.com/CertCom/game/binary_game_page.htm
Trinity High School
Page 7
N4/ N5 Computing Science
Data Representation
Representing Large (Real) Numbers
Computers can store very large numbers, however they have to lose some accuracy to
do this. The numbers are stored in Floating Point format. For example, a decimal
number such as 123 456 789 can be shown as 0.123456789 x109 . The number
0.123456789 is the mantissa and the number 9 is the exponent.
The numbers stored in a computer are, of course, binary numbers. A binary number
stored in floating point form might be:
1001011010010110 x210010110
The same system is used to store non-integer (real) numbers.
Trinity High School
Page 8
N4/ N5 Computing Science
Data Representation
Representing Graphics
Representing Black & White Bitmapped Graphics
One way that the computer represents graphics is using tiny dots called pixels. A pixel is
a picture element, the smallest element of a bitmapped graphic. Each pixel in a black
and white bitmapped graphic uses 1 bit to represent and store its colour. The bit value
is either 1 or 0 (1=black, 0=white), for example:
Screen representation
0
0
1
1
1
1
0
0
0
1
0
0
0
0
1
0
1
0
1
0
0
1
0
1
1
0
0
0
0
0
0
1
1
0
1
0
0
1
0
1
1
0
0
1
1
0
0
1
0
1
0
0
0
0
1
0
0
0
1
1
1
1
0
0
Stored in memory
Resolution
The term ‘resolution’ is the number of pixels in a fixed area. High resolution graphics
have a high number of small pixels; low resolution graphics has a small number of large
pixels. High resolution graphics give better quality than low resolution graphics but
require more storage. Resolution is usually measured in dpi (dots per inch).
Trinity High School
Page 9
N4/ N5 Computing Science
Data Representation
Calculating the Size of a Black and White Bitmapped Graphic
Calculating the storage requirements of a bitmapped graphic is quite straight forward.
The total number of pixels can be worked out by multiplying the number of pixels
across by the number of pixels down (width x height). As one bit is needed per pixel,
the number of pixels equals the number of bits. If you then divide the total number of
pixels by 8 you can work out the number of bytes (remember 8bits = 1 byte). For large
(or high resolution) graphics you may have to divide by 1024 to show you answer in
kilobytes etc…
In short:
File size in bytes = width x height (pixels)
8
e.g. Calculate the file size of a black and white bitmapped graphic measuring 2666 pixels
wide by 1764 pixels high, showing your answer in kilobytes:
File size in bytes =
=
Files size in kilobytes =
=
2666 x 1764 (bits)
8
587853 bytes
587853
1024
574.075 KB
Colour Depth
The number of bits that are used to code the colour of each pixel is called the bit depth.
An image with only 1 bit depth will only represent 2 colours – Black and White. An
image with 24 bit depth will be able to represent 16777216 colours.
The pictures below show you how the same graphic would be represented depending
on the bit depth and how the greater the bit depth, the higher the quality:
1 bit: 2 colours
2 bits: 4 colours
Trinity High School
4 bits: 16 colours
8 bits: 256 colours
24 bits: 16777216
colours
Page 10
N4/ N5 Computing Science
Data Representation
Calculating the Size of a Colour Bitmapped Graphic
The process of calculating the size of a colour bitmapped graphic is similar to the
calculation for a black and white graphic. The only difference is that the number of bits
used to represent the colour of each pixel (bit depth) has to be considered.
File size in bytes = width x height (pixels) x bit depth
8
e.g. Calculate the file size of a black and white bitmapped graphic measuring 2457 pixels
wide by 1635 pixels high with a bit depth of 16 bit, showing your answer in megabytes:
File size in bytes =
=
Files size in kilobytes =
=
2457 x 1635 x 16 (bits)
8
8034390 bytes
8034390
1024
7846.08 KB
File size in megabytes =
7846.08
1024
=
7.66 MB
Vector Graphics
Vector graphics information is stored rather differently from bitmapped graphics.
Instead of storing information about each pixel, vector graphics are made up of layered
objects, each of which has a description of its attributes stored.
A typical object might be described as:
Line(layer, startX, startY, endX, endY, line colour, line thickness, line pattern)
Because of the way in which vector graphics are stored they have a much smaller file
size than bitmapped graphics. They can also be scaled up without loss of resolution.
Another feature is that the individual objects can be edited independently without
affecting the other objects.
Trinity High School
Page 11
N4/ N5 Computing Science
Data Representation
Bitmapped v Vector
There are some key differences between bitmapped and vector graphics, both have
some advantages and disadvantages. These are summarised below:
Vector
Bitmapped
Can be scaled to large sizes keeping
original quality
Scaling causes pixilation
Individual objects can be edited
Only the image as a whole can be edited
Are easily converted to bitmap formats
Are very difficult to convert to vector
formats
File sizes are relatively small
File sizes can be very large
Difficult to create realistic images
Images can very very realistic (e.g. digital
photograph
Activity
1. What are the tiny dots that make up a graphic called?
2. Explain how bit mapped graphics are stored by a computer.
3. Explain the meaning of the term 'resolution' when referring to a bitmapped image.
4. What is the relationship between resolution and file size in a bitmapped graphic?
Trinity High School
Page 12
N4/ N5 Computing Science
Data Representation
5. Complete the bit map for the 8 × 8 image below.
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
1
1
0
1
1
1
1
0
1
1
0
1
0
0
1
0
1
1
0
1
0
0
1
0
1
1
0
1
1
1
1
0
1
1
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
6. Calculate the storage requirements for the above image. Show all of your working.
7. How much storage space is required to store a black and white image that is 4 inches
long and 3 inches tall at a resolution of 200 dpi? Give your answer in kilobytes and show
all your working.
Trinity High School
Page 13
Download