Presentation is loading. Please wait.

Presentation is loading. Please wait.

COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.

Similar presentations


Presentation on theme: "COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1."— Presentation transcript:

1 COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1

2 Review Convert from base 10 to 2, 8, 16 41 10 Base 2: 101001 Base 8: 51 Base 16: 29 2

3 BINARY ARITHMETIC ADDITION, SUBTRACTION, MULTIPLICATION, DIVISION 3

4 Binary Arithmetic: Addition and Subtraction Addition 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0 (carry: 1) Subtraction 0 – 0 = 0 0 – 1 = 1 (borrow: 1) 1 – 0 = 1 1 – 1 = 0 4

5 Binary Addition: Example Note: Incase of adding 3 1’s. Instead of the sum being 0 with a carry of 1, the sum is 1 with a carry of 1. 5

6 Binary Subtraction: Examples Note: After borrowing from the next digit, 0 becomes 1 0 and not 1. 1 0 becomes 1 when borrowed from. 6

7 Binary Addition and Binary Subtraction Practice 1. Add 10110 and 01110 2. Subtract 1011 from 11001 3. Add 11100 and 01010 4. Subtract 010 from 1001 7

8 Binary Arithmetic Multiplication Multiplication  0 x 0 = 0  0 x 1 = 0  1 x 0 = 0  1 x 1 = 1 Note: When multiplying, add two of the partial products at a time to prevent mistakes that my occur from adding many numbers 8

9 Binary Multiplication Practice 1. Multiply 1001 and 1100 2. Multiply 1101 and 1111 3. Multiply 0001 and 0101 4. Multiply 1010 and 11011 9

10 SIGNED NUMBERS 3 WAYS TO REPRESENT 10

11 Method 1: Sign And Magnitude  Obvious solution: sign and magnitude  define leftmost bit (most significant bit) to be sign!  0 => +(positive), 1 => - (negative)  Rest of bits can be numerical value of number  MIPS uses 32-bit integers. +1then would be: 0000 0000 0000 0000 0000 0000 0000 0001  And - 1 in sign and magnitude would be: 1000 0000 0000 0000 0000 0000 0000 0001 11

12 Method 2: 1’s Complement  Complement the bits  Example: 7 10 = 00111 2 -7 10 = 11000 2  What is -00000 ? 000000000101111... 11111 1111010000... 12

13 Method 3: 2’s Complement  Method 1: Subtract from 2 n. For Example 3: 0011, n = 4 -3: 10000 (2 n ) – 0011 = 1101  Method 2: Complement and add 1 3: 0011-3: 1100 + 1 = 1101  The leftmost bit of a signed binary numeral indicates the sign  0 (+), all the bits are the numerical value of number  1 (-), all the bits are inverted then 1 is added to the result ► Remember for positive numbers, just make sure a 0 is the MSB. You do not need to convert it using the formula above! 13

14 Signed Number Representation Table 14

15 Signed Number Representation Practice 1. Represent each negative number as an 8 bit binary number using a) sign and magnitude, b) 1’s complement, and c) 2’s complement. -15-78-45-101-127 15

16 Addition/Subtraction using 2’s Complement  Subtraction = Addition with opposite sign. 4 – 6 = 4 + (-6) = -2 4:0100 -6:1010(2’s complement) 1110 16 Sign bit =-2

17 Overflow Error: Sum Is Too Large  4 bit binary with 2’s complement representation has a number range between -8 and 7  What happens if 6 + 4? (-7) + (-2)? 6:0110-7:1001 4:0100-2:1110 10100111 17 Sign bit = 1 (negative) Sign bit = 0 (positive)

18 Overflow Error: Cont’d…  Only 2 cases where overflow can occur:  Sum of 2 positive numbers yields a negative result  Sum of 2 negative numbers yields a positive result  Note: We always ignore the carry to ensure number of bits does not change. 18

19 2’s Complement Addition/Subtraction Practice Convert the following decimal numbers into 6 bit binary and then solve using 2’s complement. Indicate if Overflow Occurs. 19 15 + 18-17 + 419 - 13 -12 - 20

20 IEEE FLOATING POINT REPRESENTATION 20

21 IEEEFloating Point Representation  Most standard floating point representation use: 1 bit for the sign (positive or negative) 8 bits for the range (exponent field) 23 bits for the precision (fraction field) 21 Note: Biased Notation. The exponent is obtained by adding 127 to the value. That is: 5 -> 132, 1-> 128, 0 -> 127, -127 ->0

22 Floating Point Exceptions Overflow & Underflow  Overflow occurs when the exponent is too large to fit in the exponent field.  Underflow occurs when the exponent is too small to fit in the exponent field. 22 Negative Overflow Negative numbersPositive Numbers Negative UnderflowPositive UnderflowPositive Overflow 0

23 Floating Point Example  How is the decimal number -6.625 represented in floating point? Show Steps of your work. 23 Thus the exponent is given by:

24 Floating Point Example Solution 24 1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

25 Floating Point Example 2  Convert the following binary floating point number into decimal 25 00111 11010110 0000 0000 0000 0000 000 FPexponent = 64+32+16+8+4+1 = 125

26 Floating Point Representation Practice  How is the decimal number -15.875 represented in floating point? Show all steps of your work.  How is the number (17.4) 16 represented in binary floating point? Show all steps of your work.  Represent (11011.101011001) 2 as floating point. Show all steps of your work. 26

27 Floating Point Practice Cont’d… 27  Convert the following binary floating point number into an un-normalized binary number 0 10001010 10011101111010000000000  Convert the following binary floating point number into decimal 1 01111101 01010000000000000000000


Download ppt "COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1."

Similar presentations


Ads by Google