Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Design and Development Storing Data Computing Science.

Similar presentations


Presentation on theme: "Software Design and Development Storing Data Computing Science."— Presentation transcript:

1 Software Design and Development Storing Data Computing Science

2 Learning Objectives By the end of this topic you will be able to: understand why computers store numbers as binary code;understand why computers store numbers as binary code; convert between binary and decimal; understand how computers store integers using two’s complement notation;understand how computers store integers using two’s complement notation; convert between a decimal integer and two’s complement notation; convert between a decimal integer and two’s complement notation; explain how computers store real numbers using floating point notation;explain how computers store real numbers using floating point notation;

3 Why Binary? Computers store data in billions of electronic switches called transistors Switches can either be on or off (two states) The easiest way to represent this is as a series of 0s and 1s

4 Human (Decimal) system 10 4 10 3 10 2 10 1 10 0 Ten Thousands ThousandsHundredsTensUnits 01356 1 x 1000 + 3 x 100 + 5 x 10 + 6 x 1 = 1356

5 Binary system 2727 2626 2525 2424 23232 2121 2020 128s64s32s16s8s4s2sUnits 00000011 2 + 1 = 3

6 Binary system 2727 2626 2525 2424 23232 2121 2020 128s64s32s16s8s4s2sUnits 00001010 8 + 2 = 10

7 Binary system 2727 2626 2525 2424 23232 2121 2020 128s64s32s16s8s4s2sUnits 00100011 32 + 2 + 1= 35

8 Binary system 2727 2626 2525 2424 23232 2121 2020 128s64s32s16s8s4s2sUnits 11111111 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1= 255 (2 8 = 256)

9 Converting Decimal to Binary Find the largest power of two which is less than the number to convert. Subtract it and repeat with the remainder.

10 Converting Decimal to Binary Convert 113 to binary 2 6 = 64 113-64 = 49 2 5 =32 49-32 = 17 2 4 =16 17-16 =1 128643216842U 1110001

11 Positive Integers 10008 10019 101010 101111 110012 110113 111014 111115 1000016 0000 0011 0102 0113 1004 1015 1106 1117

12 Negative Integers (Using a sign-bit) 1001 -1 1010-2 1011-3 1100-4 1101-5 1110-6 1111-7 There are two problems with this method 1000 and 0000 both mean zero Adding a positive number to a negative number gives the wrong answer

13 Why adding integers using the sign-bit method doesn’t work 1011-3 0100+4 1111-7 +

14 Two’s Complement (8 bits) 2727 2626 2525 2424 23232 2121 2020 -128s64s32s16s8s4s2sUnits 00000011 2 + 1 = 3 Make the most significant bit negative

15 Two’s Complement (8 bits) 2727 2626 2525 2424 23232 2121 2020 -128s64s32s16s8s4s2sUnits 10000011 -128 + 2 + 1 = -125

16 Two’s Complement (8 bits) 2727 2626 2525 2424 23232 2121 2020 -128s64s32s16s8s4s2sUnits 10001010 -128 + 8 + 2 = -118

17 Storing numbers using Two’s Complement (3 bits) In this example the 4s column is the sign bit 010+2 001+1 000 0 111-1 110-2 101-3

18 Addition now works and there is only one code for zero 0113 100-4 111-1 +

19 Converting a negative decimal number 1.Establish the bit length required 2.Convert positive number to binary 3.Complement the binary number 4.Add 1

20 -3 (8 bits) 1.+3 = 00000011 2.Complement 11111100 3.Add 1 +1 4.Result11111101

21 -15 (8 bits) 1.+15 =00001111 2.Complement 11110000 3.Add 1 +1 4.Result11110001

22 -35 (8 bits) 1.+35 =00100011 2.Complement 11011100 3.Add 1 +1 4.Result11011101

23 Real Numbers Real numbers are stored using Floating Point notation A Floating Point number takes up more memory than a two’s complement number and may be less accurate

24 Scientific Notation You will be familiar with how numbers like this are stored in the Decimal system: 1.34 X 10 3 Mantissa Exponent = 1340

25 Scientific Notation The exponent can be positive or negative 1.34 X 10 -3 Mantissa Exponent = 0.00134

26 Floating Point Notation Computers use a similar system called floating point notation For example 18.75 in binary is 10010.11 10010.11 =.10010 x 2 101 Exponent Mantissa The Exponent is a power of two stored in Two’s Complement notation because it can be positive or negative

27 Floating Point Notation The number of bits allocated to the Exponent determine the range of numbers you can store The number of bits allocated to the Mantissa determine the accuracy of the numbers you can store.

28 Range The exponent is an integer stored as a 2’s complement number 8 bits allocated to the exponent means it can represent a range of numbers between 2 127 and 2 -128

29 Accuracy The Mantissa is an integer stored as an unsigned (positive) number The larger the number of bits allocated to the mantissa, the more accurate the number will be

30 Floating Point Notation Floating Point Notation will always be a compromise between how accurately you can store a number and how wide a range of numbers you wish to store. For example if your floating point numbers as stored in 5 bytes (40 bits) you could allocate 32 bits to the mantissa and 8 bits to the exponent. If you wanted a more accurate number you would have to increase the number of bits allocated to the mantissa which would reduce the number available to the exponent


Download ppt "Software Design and Development Storing Data Computing Science."

Similar presentations


Ads by Google