Data Representation

Download Report

Transcript Data Representation

Data Representation
The storage of
Text
Numbers
Graphics
As everything in binary is to do with powers of 2,
we don’t use thousands, millions, billions etc.
1 bit (binary digit) = 0 or 1
(23)
8 bits
= 1 byte
(210) 1024 bytes = 1 Kilobyte
(220) 1024 Kb
= 1 Megabyte
(230) 1024 Mb
= 1 Gigabyte
(240) 1024 Gb
=
1 Terabyte
Data Representation
ASCII is a 7 bit code giving a unique code for 128
characters.
The first 32 are CONTROL CODES which make
something happen.
The rest are alphanumeric characters on the keyboard.
As computers use 8 bits as a minimum, this allows an
extended ASCII set to include symbols like square
root, some foreign letters etc.
Data Representation
Even with 8 bits for ASCII there are only 256
possibilities, not nearly enough to code alphabets from
other languages
UNICODE solves this problem. Unicode uses 16 bits
for each character giving 65 536 different codes. This
proves sufficient to code all the main alphabets of the
world.
Data Representation
In base 2 binary, the headings are powers of two
Headings:
Number
….
8
4
2
1
1
1
1
0
Giving 1 eight
1 four
1 two
0 units
making 14 in decimal
Data Representation
To change any binary number to decimal (denary):
Put the headings 2n …. 25 24 23 22 21 20 above the
number. Add up the headings where there is a one.
Example: 1100011
64
32
16
8
4
2
1
1
1
0
0
0
1
1
64 + 32 + 2 + 1 = 99
Data Representation
To change any decimal number to binary you divide repeatedly
by 2. The remainders become the binary number.
Example 57
2 | 57
2 | 28 R 1
2 | 14 R 0
2| 7 R 0
2| 3 R 1
2| 1 R 1
0 R 1
=111001
Data Representation
However, you can more easily work it out from the
headings
E.g. 46
This needs a 32 an 8 a 4 and a 2
32
16
8
4
2
1
1
0
1
1
1
0
Data Representation
In two’s complement, you represent a negative by:
Write its positive value in binary
Flip each bit (1  0, 0  1)
Add 1
Example: -18 using 8 bit numbers.
18 =
00010010
Flip
11101101
Add 1
11101110
Data Representation
How do you find the value of a two’s complement number?
Flip and add 1 to get the value. (i.e. do the 2’s complement again)
Eg 11001011
This is -ve because it begins with a 1
Flip :
00110100
Add 1 :
00110101
= 53, so the original number was –53.
Data Representation
In storing numbers the computer always sets aside the same
amount of storage locations in RAM. It doesn’t matter if the
number is 3 or 5 billion.
Let’s say it just sets aside 1 byte for integers.
8 bits can hold 28 = 256 different values
With 2 bytes for each integer:
16 bits can hold 216 =65 536 different values.
Data Representation
Now if 8 bits can hold 28 = 256 different values
The RANGE is 0 to 255
With 2 bytes for each integer:
16 bits can hold 216 =65 536 different values.
The RANGE is 0 to 65 535
Data Representation
Usually 4 bytes are set aside for integer variables.
For positive numbers this gives 232 different values.
With a range from 0 to 232 - 1
This is: 0 to 4 294 967 293
Data Representation
For n bits there are :
2n different values
So the RANGE is
0 to 2n - 1
Data Representation
For decimals Computers use
The point floats to the FRONT of the number.
Take 93 000 000
This can be written .93 x 108
Why bother with the 10?
Write it as .93 8
Why bother with the point?
A computer stores it as
93
8
Data Representation
The floating point number
93
8
Is made up of a MANTISSA: 93
And an EXPONENT: 8
Of course all this is done in binary on the computer with
two’s complement for negatives.
Data Representation
With floating point storage locations have to be set
aside for both the mantissa and the exponent.
Decisions have to be made about how many bits for the
mantissa and how many for the exponent. As you have
seen this affects the range of values that can be stored.
Data Representation
If you increase the storage for the mantissa you
increase the PRECISION (accuracy) that real numbers
can be stored in (more significant figures).
If you increase the storage for the exponent, you
increase the RANGE of numbers that can be stored.
Data Representation
Computer pictures / images are made up of dots on paper,
called pixels on a display.
A typical printer will print 600 or 1200 dpi.
A monitor displays 72 or 90 dpi.
In black and white these pixels can be stored as a 1 or a 0.
So one bit per pixel.
Resolution is the number of pixels or dots used.
Data Representation
To store colours, you need more than one bit per pixel.
Colour depth is the name for how many bits are stored per
pixel for colours.
1 bit gives 21 colours = 2
2 bits gives 22 colours = 4
3 bits gives 23 colours = 8
4 bits gives 24 colours = 16
8 bits gives 28 colours = 256
16 bits gives 216 colours = 65536
24 bits gives 224 colours = 16 777 216 (called true colour)
Data Representation
If this was part of a screen
using 4 colours
00
white
01
green
0100100001010101
10
red
0101011001010101
11
black
0111110010010101
Then it would be stored as
shown on the left.
0000110101100101
Data Representation
If a computer screen has 1024 pixels along and 768 up and
had 256 colours
You need 8 bits per pixel:
1024 x 768 x 8 = 6291456 bits
6291456 / 8 = 786432 bytes
786432 / 1024 = 768 Kb approx.
Data Representation
If a graphic measuring 2” by 4” is scanned at 600 dpi using
true colour, what is the storage requirement for the scan?
True colour needs 24 bits per pixel
2 x 4 x 600 x 600 x 24 = 69 120 000 bits
69 120 000 / 8 = 8 640 000 bytes
8 640 000 / 1024 = 8 437.5 Kb
8 437.5 / 1024 = 8.25 Mb approx.
Data Representation
Graphics that are stored pixel by pixel are called
BITMAPS.
Every pixel (and its colour) is mapped to a set of bits in
memory or on backing storage.
There is another type of graphic storage called VECTOR
GRAPHICS.
Data Representation
Vector Graphics store graphics as individual objects.
Text is an object, a square, a circle, a line etc.
Each object has ATTRIBUTES.
For instance in a graphics package a rectangle might be object
number 3.
Attributes would be things like the co-ordinates of the corners,
the line colour, fill colour etc.
Data Representation
So a rectangle might be stored as :
3, 100, 200, 400, 800, 2, 3, 5
3 means rectangle.
100, 200 is the screen co-ordinates of the bottom left corner.
400, 800 the co-ordinates of the top right corner.
2 is the colour of the line
3 the line thickness
5 the fill colour.
Data Representation
Differences between bitmap and vector graphics:
Bitmaps use a large amount of storage
You can rub out parts of a bitmap
You can use paint effects in bitmap.
You cannot improve the resolution of a bitmap on a better device.
Vector graphics only store the objects, not the whole screen.
You can edit objects in vector graphics (resize, change colour etc)
You can change layers (e.g. bring to front)
Resolution independent (e.g. print better quality on a better printer)
Data Compression
Because bitmaps can have such large files we need
data compression for storing or transmitting them.
A 5 Megapix camera using true colour needs 15 Meg
for each photo.
Because of this data compression is needed, for
instance jpeg could reduce that 15 Meg photo to 2
Meg without any noticeable loss of quality.