Presentation is loading. Please wait.

Presentation is loading. Please wait.

Number Systems Part 2 Numerical Overflow Right and Left Shifts Storage Methods Subtraction Ranges.

Similar presentations


Presentation on theme: "Number Systems Part 2 Numerical Overflow Right and Left Shifts Storage Methods Subtraction Ranges."— Presentation transcript:

1 Number Systems Part 2 Numerical Overflow Right and Left Shifts Storage Methods Subtraction Ranges

2 Numerical Overflow An overflow is when something doesn’t fit in a certain space Numeric overflow is when the storage for a calculation is too small to hold the result For example we have an 8 bits register, if we add two binary numbers and the result turns out to be 9 bits it would not fit in the register

3 Example Let’s say we have an 8 bit register Add the following; Do we have an overflow? 11111111+ 10101010

4 Numerical Overflow When we have a numeric overflow we will have an error in our calculation When we have an overflow we would need to remove the extra bit at the start of the number Lets say we had a 7 bit register and the result of a calculation is 11001100 the actual answer would be 1001100

5 Example Let’s say we have a 7 bit register Add the following; Do we have an overflow? Actual answer = 1101111 + 1101101

6 Working Suppose we have a 4 bit registers. 1. Perform the additions 2. Is there and overflow? 3. What is the actual answer? 1110+0101+ 1101+ 11110110 0100

7 Answers 1110+0101+ 1101+ 11110110 0100 111011011 10001

8 What is Bit Shifting? Bit shifting is the process of moving all the bits in a binary number We have two shifts 1. A right shift 2. A left shift The right shift would divide the number while the left would multiply it

9 Right Shift The right shift is used to perform divisions Hence if we where to perform three right shifts we would be diving the number by 2 three times For example if we shift 10110011 2, = 179 10 right by three places, we get 00010110 2 = 22 10  179 /2 = 89  90/2 = 44  45/2 = 22

10 How Right Shifts work Lets say we have 1100101 2 and we wish to perform 2 right shifts 1100101 1 st Shift right 0110010 1 LOST 0 ADDED 2 nd Shift right 0011001 0 ANS =

11 Working Shift the numbers to the right by the number of shifts indicated in the brackets; 1. 1000110 (2) 2. 1110001 (4) 3. 1111000 (1) 4. 01010101 (4) 5. 0000111 (3) Change to decimal to check your answers

12 1000110 701110001 1131111000 120 0100011 350111000 560111100 60 0010001 170011100 28 0001110 14 0000111 7 01010101 850000111 7 00101010 420000011 3 00010101 21 00001010 10 00000101 5 0000001 1 0000000 0

13 Left Shift The left shift is used to perform multiplications Hence if we where to perform four left shifts we would be multiplying the number by 2 four times If any bits are lost when shifting left the result is no longer accurate For example if we shift 01100101 2, = 101 10 left by one place, we get 11001010 2 = 202 10  101 x 2 = 202

14 How Left Shifts work Lets say we have 01100101 2 and we wish to perform 2 left shifts 01100101 11001010 0 LOST 10010100 1 Answer no longer correct as a 1 was lost 1 st Left Shift 2 nd Left Shift

15 Working Shift the numbers to the left by the number of shifts indicated in the brackets, also state which answers are not correct. 1. 0000110 (4) 2. 1110001 (3) 3. 0011110 (1) 4. 01010101 (2) 5. 0000111 (3) Change correct answers to decimal to check your answers

16 0000110 611100010011110 30 0001100 1211000100111100 60 0011000 24 0110000 48 1100000 96 1000100 0001000 Not correct 010101010000111 7 101010100001110 14 01010100 Not Correct 0011100 28 0111000 56

17 Storage Methods When we have a fixed register we might want to store out binary number in a certain way The three ways are using; 1. sign and magnitude (first digit is 0 = positive, first digit is1 = negative) 2. one’s complement 3. two’s complement.

18 Example 1 Lets say we have a register of 8-bits and we wish to store the number 14 10 Since the number is positive, all we need to do is convert it to binary and store it It would be the same in the three different storage methods, 14 10 = 00001110 2

19 Example 2 Lets say I have an 8 bit register and want to store -14 10 The number now changes since it is negative, we first change it to binary = 00001110 2 Sign and Magnitude 10001110 Note that the fist digit is 1 because in this case 14 is a negative number. One’s Complement 11110001 In this case we simply applied NOT on the binary value of 14. Two’s Complement 11110010 We change the binary number 14 into two’s complement

20 Working Convert the following to; a) Sign and magnitude b) One’s Complement c) Two’s Complement Size of register is indicated in the brackets. 1. 33 10 (8) 2. -60 10 (9) 3. -44 10 (7) 4. 10 10 (5) 5. -74 10 (10)

21 Subtraction We are able to subtract using binary numbers thanks to Two’s Complement When we need to subtract in binary we first need to change the negative number to Two’s Complement if we have 22 – 10 we have to change 10 to Two’s Complement then perform an addition Binary numbers must be of the same length in order to subtract in binary

22 Example We want to perform the following subtraction in binary; 22 -10110 - 10110+ 1001010 10110 12 101100 Change to Binary Two’s Complement Overflow

23 Working Perform the following subtractions in binary; 1. 30-20 2. 100 – 50 3. 50 – 25 4. 5 – 2 5. 66- 60

24 Ranges A ranges determines the lowest and the highest values which can be represented by a certain register We will be going through two types of ranges using binary; 1. normal binary 2. two’s complement.

25 Normal Binary What is the range of numbers which can be represented using 8-bits? Since we have 8 Bits, the maximum value represented in binary is 11111111 and the smallest is 00000000. If we convert these numbers to decimal we end up with: 0 to 255

26 Example What is the range of numbers which can be represented using 5-bits? Since we have 5 Bits, the maximum value represented in binary is 11111 and the smallest is 00000. If we convert these numbers to decimal we end up with: 0 to 31

27 Two’s Complement What is the range of numbers which can be represented using 8-bits in two’s complement? The first number in two’s complement identifies the number as a negative number, the highest possible positive number is 01111111 2 = 127 10 To find the smallest number we convert the positive number to negative so in this case -127 10. The range is: -127 to 126 (126 due to the 0)

28 Example What is the range of numbers which can be represented using 10-bits in two’s complement? 0111111111 2 = 511 10 511 10 becomes negative to show the smallest number helps = -511 10. The range is: -511 to 510


Download ppt "Number Systems Part 2 Numerical Overflow Right and Left Shifts Storage Methods Subtraction Ranges."

Similar presentations


Ads by Google