12
Shawlands Academy Higher Computing Data Representation

Shawlands Academy Higher Computing Data Representation

Embed Size (px)

Citation preview

Page 1: Shawlands Academy Higher Computing Data Representation

Shawlands Academy

Higher Computing

Data Representation

Page 2: Shawlands Academy Higher Computing Data Representation

1 Data Representation1.2 Numbers

• Numbers are converted to binary – number base 2

• Example of 154 represented as a binary number

128 64 32 16 8 4 2 1

1 0 0 1 1 0 1 0

128 +0 +0 +16 +8 +0 +2 +0 =154

Page 3: Shawlands Academy Higher Computing Data Representation

1 Data Representation1.2 Numbers

2 69

2 34 R1

2 17 R0

2 8 R1

2 4 R0

2 2 R0

2 1 R0

2 0 R1

How to convert decimal to binary e.g. 69

Giving 1000101

•Keep dividing by 2

•Note the remainders

•Read the remainders from the bottom up

Page 4: Shawlands Academy Higher Computing Data Representation

Range of Numbers

• Using 1 byte for storage gives 256 (28) possible numbers in the range 0 - 255

• 2 bytes gives 65536(216), 0 - 65535

• Increasing the size of the storage for numeric data increases the range of numbers which can be stored.

Page 5: Shawlands Academy Higher Computing Data Representation

Data Representation1.3 Integers

• Positive numbers Converted directly to binary 2 bytes = 16 bits gives 0 to 216-1 or 0 to 65535

Page 6: Shawlands Academy Higher Computing Data Representation

Negative Numbers

• - more difficult

• One of the 16 bits available has to be used to store the sign (- or +) – this reduces the range of numbers to

–32768 to 32767

This is called Signed Bit representation

Page 7: Shawlands Academy Higher Computing Data Representation

Problems with Signed Bit Representation

• Does not always work because:

• Addition does not work properly (-5+-10 gives 15)

• Two values for 0 (00000000 and 10000000)

Page 8: Shawlands Academy Higher Computing Data Representation

To overcome problemsTwos Complement

– Addition works and there is only one zero

– All 0’s are converted to 1’s and 1’s to 0’s then 1 is added.

– To convert 5 to –5

0 0 0 0 0 1 0 1

1 1 1 1 1 0 1 0

+1

1 1 1 1 1 0 1 1

OR 5

OR -5

Page 9: Shawlands Academy Higher Computing Data Representation

Data Representation1.4 Real Numbers

• Real numbers are stored as floating point.

• E.g 34008.6 is .340086*105

• In binary 1101.1001 is .11011001*2100 (the 4is 100 in binary)

• The mantissa is 11011001 and the exponent is 100

• Usually 4 bytes used for mantissa and 2 for exponent

• Increasing the size of the mantissa increases accuracy

• Increasing the size of the exponent increases the range of numbers which can be stored

Page 10: Shawlands Academy Higher Computing Data Representation

1 Data Representation1.1 Text

Each character is stored as an 8 bit binary code

This is called the ASCII system. E.g. A is stored as 65 (01000001 in

Binary). 1 byte can store 256 (28)different characters

– enough for all the keys on the keyboard and several foreign symbols (for currency etc )

Page 11: Shawlands Academy Higher Computing Data Representation

Data Representation1.5 Bit-mapped Graphics

• For a graphic drawn in a painting package the computer stores the data as a 2 dimensional array of pixels.

• Each pixel in a black and white image is 1 bit in memory.• 2 bits can store 4 colours or shades of grey.(22)• 8 bits can store 256 colours.(28)

• 2 bytes can store 65,536 colours.(216)• Bit mapped images are often generated from scanned

pictures and can create huge files.• Editing can be performed at pixel level.• When images are enlarged they can become “lumpy” and

lose definition.

Page 12: Shawlands Academy Higher Computing Data Representation

Data Representation1.6 Vector Graphics

• Sometimes called object-orientated graphics.• Used in CAD, drawing and publishing packages.• Describes an object by its attributes (start & end

positions, thickness & colour of lines etc.)• Editing at pixel level not possible.• Can be resized without losing original sharpness.• Can be placed over another graphic without

rubbing it out as happens with bit-mapped.