higher computing

33
Higher Computing Data Representation

Upload: elom

Post on 09-Jan-2016

28 views

Category:

Documents


0 download

DESCRIPTION

Higher Computing. Data Representation. What we need to know!. Representation of positive numbers in binary including place values and range up to and including 32 bits. Conversion from binary to decimal and vice versa. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Higher Computing

Higher Computing

Data Representation

Page 2: Higher Computing

What we need to know!

•Representation of positive numbers in binary including place values and range up to and including 32 bits.

•Conversion from binary to decimal and vice versa.

•Conversion to and from bit, byte, Kilobyte, Megabyte, Gigabyte, Terabyte. (Kb, Mb, Gb, Tb)

•Description of the representation of negative numbers using two’s complement using examples of up to 8 bit numbers.

•Description of the relationship between the number of bits assigned to the mantissa/exponent and the range and precision of floating point numbers.

Page 3: Higher Computing

How we count in decimal

• Remember how we count.Decimal Thousands Hundreds Tens Units

104 103 102 101

Number of combinations

10000 1000 100 10

• Each column can have 10 different values in it. Making Decimal a Base 10 number system.

• Binary can only have 2 different values.• Binary is a Base 2 number system.

Page 4: Higher Computing

Binary representation of positive numbers (Cont.)

• Using a table like this you can work out the values of binary numbers.

232 230 220 216 210 29 28

4294967296 1073741824 1048576 65536 1024 512 256

Binary 27 26 25 24 23 22 21 20

No. of Combinations

128 64 32 16 8 4 2 1

Page 5: Higher Computing

Binary ranges

No of Digits

Max Number and Range Calculation

8 256 numbers, from 0 to 255

28= 256

16 65536 numbers, from 0 to 65535

216 = 65 536

24 16 777 216 numbers, from 0 to 16 777 215

224 = 16 777 216

32 4 294 967 296 numbers, from 0 to 4 294 967 295

232 = 4 294 967 296

Page 6: Higher Computing

Conversion from binary to decimal

• E.g. an 8- bit binary number 10010011

27 26 25 24 23 22 21 20

1 0 0 1 0 0 1 1

= 27 + 24 + 21+20

= 128 + 16 + 2 + 1

= 147

Page 7: Higher Computing

Conversion from decimal to binary

• Given the binary number 150.

• Divide by 2 = 75 r 0

• Divide by 2 = 37 r 1

• Divide by 2 = 18 r 1

• Divide by 2 = 9 r 0

• Divide by 2 = 4 r 1

• Divide by 2 = 2 r 0

• Divide by 2 = 1 r 0

• Divide by 2 = 0 r 1

The binary value is = 10010110

Page 8: Higher Computing

Conversion to and from a byte, Kilobyte, Megabyte

• There are 1024 bytes in a kilobyte and 1024 kilobytes in a megabyte so to turn bytes into megabytes you divide once by 1024 to turn them into kilobytes and again by 1024 to turn them into megabytes.

• 1 048 576 bytes = 1 048 576/1024 = 1024 kilobytes

• 1024 kilobytes = 1024/1024 = 1 Megabyte

Page 9: Higher Computing

Conversion between bytes, Kilobytes, Megabytes,

Gigabytes • There are 1024 megabytes in a gigabyte so

we calculate the number of megabytes and then dive by 1024 to turn them into gigabytes.

• 4 294 967 296 bytes = 4 294 967 296/1024 = 4 194 304 kilobytes

• 4 194 304 kilobytes = 4 194 304/1024 = 4096 megabytes

• 4096 megabytes = 4096/4 = 4 gigabytes

Page 10: Higher Computing

Conversion between Gigabytes and Terabyte.

• There are 1024 gigabytes in a terabyte so we calculate the number of gigabytes and then dive by 1024 to turn them into terabytes.

• 512 gigabytes = 512/1024 = 0.5 terabytes

Page 11: Higher Computing

Negative numbers• Storing negative numbers in a computer system make it

necessary to store the sign of the number.

• One method of doing this is to use the most significant bit to represent positive or negative.

– 9= 1000 1001 and –9 = 0000 1001• This means the range of values stored would be reduced.• 8 bits would us 7 bits for the actual number 27 = 128• There are also two values for zero.• 1000 0000 and 0000 0000

Page 12: Higher Computing

Two’s complement

• To convert an negative number into two’s complement you must first take the magnitude of the value and convert to binary.E.g. -9 9 in binary = 1001

• Then change all the 1 to 0 and vice versa.1001 becomes 0110

• Finally add 10110 + 1 = 0111

• Notice two’s complement also retains the leftmost bit as a signed bit

Page 13: Higher Computing

Real numbers

• Decimal fractions look like this:

Fraction 1/10 1/100 1/1000 1/10000

Decimal 0.1 0.01 0.001 0.0001

•Binary fractions look like this:

Fraction 1/2 1/4 1/8 1/16

Decimal 0.5 0.25 0.125 0.0625

Binary 0.1 0.01 0.001 0.0001

Page 14: Higher Computing

Floating point numbers• First of all look at a real number in decimal.• 15.25 = .1525 x 100 = .1525 x 102

• Any number can be written as:Mantissa x baseExponent

• The above example can be written as:• 1111.01 = .111101 x 24 = .111101 x 2100

• Decimal numbers are base 10.• Binary numbers are base 2. This is always the case

so the computer doesn’t need to store this.

=15 =0.25.

Page 15: Higher Computing

Floating point numbers (Cont.)

• 1111.01 = .111101 x 24 = .111101 x 2100

• If the decimal point is always in the same position all that needs stored is the mantissa and the exponent.

• This leaves us with

• 111101 100

mantissaExponent

Page 16: Higher Computing

Precision and range of floating point numbers

• Precision– The more bits set aside for the mantissa, the

more precise the number will be.– If there are not enough bits then the system

has to round down loosing precision.

Page 17: Higher Computing

Precision and range of floating point numbers

• Range– Increasing the number of bits used to represent

the exponent increases the range of numbers that can be represented.

Page 18: Higher Computing

What we should now know!

•Representation of positive numbers in binary including place values and range up to and including 32 bits.

•Conversion from binary to decimal and vice versa.

•Conversion to and from bit, byte, Kilobyte, Megabyte, Gigabyte, Terabyte. (Kb, Mb, Gb, Tb)

•Description of the representation of negative numbers using two’s complement using examples of up to 8 bit numbers.

•Description of the relationship between the number of bits assigned to the mantissa/exponent and the range and precision of floating point numbers.

Page 19: Higher Computing

What we need to know!• Description of Unicode and its advantages over ASCII.• Description of the bit map method of graphic representation

using examples of colour/greyscale bit maps.• Description of the relationship of bit depth to the number of

colours using examples up to and including 24 bit depth (true colour).

• Description of the relationship between the bit depth and file size.

• Description of the vector graphics method of graphic representation.

• Explanation of the need for data compression using the storage of bit-map graphic files.

• Description of the relative advantages and disadvantages of bit mapped and vector graphics.

Page 20: Higher Computing

ASCII

• American Standard Code for Information Interchange is a method of representing all the characters in memory.

• Each character is given it’s own ASCII code.• ASCII is a 7-bit code with the 8th bit being used

as a parity bit.• The 7 bit provide 128 possible values for the text.• This gives us 96 characters and 32 control codes. • Many systems use extended ASCII code which is

an 8-bit code giving a range of 256 characters

Page 21: Higher Computing

Description of Unicode• Unicode is a 16-bit code supporting 65 536 characters. • The first 256 values in Unicode are used to represent

ASCII code. • Of the 65 536 characters, 49000 codes are predefined

and 6400 are reserved for private use. • This still leaves around 10000 characters in the code

not yet made use of.• Unicode file sizes are large because it takes 2 bytes to

store each character, in contrast to ASCII which takes only 1 byte.

Page 22: Higher Computing

The bitmap method of graphics representation

• Bitmap representation of graphics means that each pixel in a graphic is represented by a series of bits / bytes. Bitmaps are typically used for creating realistic images, e.g. photographs, the output of paint packages.

• In the simplest example each pixel is represented by 1 bit.

=

1 1 1 0 1 1 1 1

0 0 0 0 0 0 0 0

1 1 1 0 1 1 1 1

1 1 1 0 1 1 1 1

1 1 1 0 1 1 1 1

1 1 1 0 1 1 1 1

1 1 1 0 1 1 1 1

1 1 1 0 1 1 1 1

=1110111 00000000 1110111 1110111 1110111 1110111 1110111 1110111

Page 23: Higher Computing

Bit depth

• The more bits assigned to represent each pixel the greater the range of colours or shades of gray that can be represented.

• This is known as the colour bit depth.

• Here the bit depth is 2 giving 22= 4 colours

01 01 01 00 01 01 01 01

00 00 00 00 00 00 00 00

10 10 10 00 11 11 11 11

10 10 10 00 11 11 11 11

10 10 10 00 11 11 11 11

10 10 10 00 11 11 11 11

10 10 10 00 11 11 11 11

10 10 10 00 11 11 11 11

=

01010100 01010101 00000000 00000000 10101000 11111111 10101000 11111111 10101000 11111111 10101000 11111111 10101000 11111111 10101000 11111111

=

Page 24: Higher Computing

Bit depth (Cont.)

Number of bits per pixel Colours, or shades of grey, represented

1 2 (black and white)

2 4

8 256

16 65 536

24 16 777 216 (true colour)

Page 25: Higher Computing

Relationship between bit depth and file size

• Let's look at the file sizes of a tiny 1 inch square graphic.

• The more bits that are used to represent a pixel the more colours you get but the greater the file size.

Resolution (pixels per square inch)

Pixels per 1 inch square graphic

Number of bits representing each pixel

File size in bytes

File size in megabytes

600 x 600 360000 8 bits(1 byte) 360000 0·343

600 x 600 360000 16 bits(2 bytes) 720 000 0·687

600 x 600 360000 24 bits(3 bytes) 1 080 000 1·030

Page 26: Higher Computing

Relationship between bit depth and file size.

• If the graphic was larger, say 6 inches square then the table looks like this:

Resolution (pixels per square inch)

Pixels per 6 inch square graphic

Number of bits representing each pixel

File size in bytes

File size in megabytes

600 x 600 12960000 8 bits(1 byte) 12960000 12·36

600 x 600 12960000 16 bits(2 bytes) 25920000 24·72

600 x 600 12960000 24 bits(3 bytes) 38 800 000 37·8

Page 27: Higher Computing

Advantages of bit-mapped graphics

• They allow the user to edit at pixel level.

• Storing a bit-mapped graphic will take the same amount of storage space no matter how complex you make the graphic.

Page 28: Higher Computing

Disadvantages of bit-mapped graphics

• They demand lots of storage, particularly when lots of colours are used.

• They are resolution dependent.This means the resolution of the graphic, the number of pixels per inch, is set when the bitmap is produced. If you reduce the resolution, the system reduces the size of the pixel grid and eliminates pixels. This reduces the quality of the image.

• You cannot isolate an individual object in a graphic and edit it.

Page 29: Higher Computing

Why is compression needed?

• You can see from the table that sizes for bit-mapped graphics can be very large.

• This means that they demand lots of storage space, and can take quite a time to transmit across a network.

• Compressing the files means that less space is required for storage and transmission times are less.

Page 30: Higher Computing

Vector graphics

• In vector graphics, the system stores mathematical definitions of: – the shape of graphic objects; – their position on the screen; – their attributes such as the fill colour, the line colour and

thickness.

• Where there are several objects in an image the vector graphic file will store information about the layering of the objects.

• The definition of a circle might hold: – the position of the centre; – the length of the radius; – the width and colour of the line marking the circumference; • the

colour/pattern of the infill.

Page 31: Higher Computing

The advantages of vector graphics

• You can edit individual objects in a graphic. • They are resolution independent. If you display the object

on a system with higher resolution output it will display perfectly in the higher resolution.

• You can build up graphics by layering objects. • They can be less demanding on storage space. A simple

graphic, for example of a circle, will take up less space than the equivalent image stored as a bitmap. However, the amount of storage required by a vector graphic varies according to how complex the graphic is. The more objects that are in the graphic, the greater the file size.

• • When you resize a vector graphic, it changes in proportion and keeps its smooth edges.

Page 32: Higher Computing

The disadvantages of vector graphics

• You cannot edit individual pixels. • A complex graphic with lots of layered

objects can demand a lot of storage space. • Vector graphics have a flat perspective

which comes from the fact that they are made up of objects filled in with a block of colour. This means they are best suited to logos, line drawings, cartoons, diagrams and simple illustrations.

Page 33: Higher Computing

What we should now know!• Description of Unicode and its advantages over ASCII.• Description of the bit map method of graphic

representation using examples of colour/greyscale bit maps.

• Description of the relationship of bit depth to the number of colours using examples up to and including 24 bit depth (true colour).

• Description of the relationship between the bit depth and file size.

• Description of the vector graphics method of graphic representation.

• Explanation of the need for data compression using the storage of bit-map graphic files.

• Description of the relative advantages and disadvantages of bit mapped and vector graphics.