number systems and arithmetic
play

Number Systems and Arithmetic Jason Mars Thursday, January 24, 13 - PowerPoint PPT Presentation

Number Systems and Arithmetic Jason Mars Thursday, January 24, 13 What do all those bits mean? bits (011011011100010 ....01) data instruction number text chars .............. R-format I-format ... integer floating point single precision


  1. Number Systems and Arithmetic Jason Mars Thursday, January 24, 13

  2. What do all those bits mean? bits (011011011100010 ....01) data instruction number text chars .............. R-format I-format ... integer floating point single precision double precision signed unsigned ... ... ... ... Thursday, January 24, 13

  3. Questions About Numbers • How do you represent • negative numbers? • fractions? • really large numbers? • really small numbers? • How do you • do arithmetic? • identify errors (e.g. overflow)? • What is an ALU and what does it look like? • ALU=arithmetic logic unit Thursday, January 24, 13

  4. Introduction to Binary Numbers • Consider a 4 bit binary number Decimal Binary Decimal Binary 0 0000 4 0100 1 0001 5 0101 2 0010 6 0110 3 0011 7 0111 • Examples of binary arithmetic 3 + 2 = 5 3 + 3 = 6 1 1 1 0 0 1 1 0 0 1 1 + 0 0 1 0 + 0 0 1 1 Thursday, January 24, 13

  5. Introduction to Binary Numbers • Consider a 4 bit binary number Decimal Binary Decimal Binary 0 0000 4 0100 1 0001 5 0101 2 0010 6 0110 3 0011 7 0111 • Examples of binary arithmetic 3 + 2 = 5 3 + 3 = 6 1 1 1 0 0 1 1 0 0 1 1 + 0 0 1 0 + 0 0 1 1 1 Thursday, January 24, 13

  6. Introduction to Binary Numbers • Consider a 4 bit binary number Decimal Binary Decimal Binary 0 0000 4 0100 1 0001 5 0101 2 0010 6 0110 3 0011 7 0111 • Examples of binary arithmetic 3 + 2 = 5 3 + 3 = 6 1 1 1 0 0 1 1 0 0 1 1 + 0 0 1 0 + 0 0 1 1 0 1 Thursday, January 24, 13

  7. Introduction to Binary Numbers • Consider a 4 bit binary number Decimal Binary Decimal Binary 0 0000 4 0100 1 0001 5 0101 2 0010 6 0110 3 0011 7 0111 • Examples of binary arithmetic 3 + 2 = 5 3 + 3 = 6 1 1 1 0 0 1 1 0 0 1 1 + 0 0 1 0 + 0 0 1 1 1 0 1 Thursday, January 24, 13

  8. Introduction to Binary Numbers • Consider a 4 bit binary number Decimal Binary Decimal Binary 0 0000 4 0100 1 0001 5 0101 2 0010 6 0110 3 0011 7 0111 • Examples of binary arithmetic 3 + 2 = 5 3 + 3 = 6 1 1 1 0 0 1 1 0 0 1 1 + 0 0 1 0 + 0 0 1 1 1 0 1 0 Thursday, January 24, 13

  9. Introduction to Binary Numbers • Consider a 4 bit binary number Decimal Binary Decimal Binary 0 0000 4 0100 1 0001 5 0101 2 0010 6 0110 3 0011 7 0111 • Examples of binary arithmetic 3 + 2 = 5 3 + 3 = 6 1 1 1 0 0 1 1 0 0 1 1 + 0 0 1 0 + 0 0 1 1 1 0 1 1 0 Thursday, January 24, 13

  10. Introduction to Binary Numbers • Consider a 4 bit binary number Decimal Binary Decimal Binary 0 0000 4 0100 1 0001 5 0101 2 0010 6 0110 3 0011 7 0111 • Examples of binary arithmetic 3 + 2 = 5 3 + 3 = 6 1 1 1 0 0 1 1 0 0 1 1 + 0 0 1 0 + 0 0 1 1 1 0 1 1 1 0 Thursday, January 24, 13

  11. Negative Numbers? • We would like a number system that provides • obvious representation of 0,1,2... • uses adder for addition • single value of 0 • equal coverage of positive and negative numbers • easy detection of sign • easy negation Thursday, January 24, 13

  12. Two’s Complement Representation • 2’s complement representation of negative numbers • Take the bitwise inverse and add 1 • Biggest 4-bit Binary Number: 7 Smallest 4-bit Binary Number: -8 Decimal Two � s Complement Binary -8 1000 -7 1001 -6 1010 -5 1011 -4 1100 -3 1101 -2 1110 -1 1111 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 Thursday, January 24, 13

  13. Two’s Complement Arithmetic (Subtraction) Decimal 2 � s Complement Binary Decimal 2 � s Complement Binary 0 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 Examples: 7 - 6 = 7 + (- 6) = 1 3 - 5 = 3 + (- 5) = -2 0 1 1 1 0 0 1 1 + 1 0 1 0 + 1 0 1 1 Thursday, January 24, 13

  14. Two’s Complement Arithmetic (Subtraction) Decimal 2 � s Complement Binary Decimal 2 � s Complement Binary 0 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 Examples: 7 - 6 = 7 + (- 6) = 1 3 - 5 = 3 + (- 5) = -2 0 1 1 1 0 0 1 1 + 1 0 1 0 + 1 0 1 1 1 Thursday, January 24, 13

  15. Two’s Complement Arithmetic (Subtraction) Decimal 2 � s Complement Binary Decimal 2 � s Complement Binary 0 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 Examples: 7 - 6 = 7 + (- 6) = 1 3 - 5 = 3 + (- 5) = -2 0 1 1 1 0 0 1 1 + 1 0 1 0 + 1 0 1 1 0 1 Thursday, January 24, 13

  16. Two’s Complement Arithmetic (Subtraction) Decimal 2 � s Complement Binary Decimal 2 � s Complement Binary 0 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 Examples: 7 - 6 = 7 + (- 6) = 1 3 - 5 = 3 + (- 5) = -2 1 0 1 1 1 0 0 1 1 + 1 0 1 0 + 1 0 1 1 0 1 Thursday, January 24, 13

  17. Two’s Complement Arithmetic (Subtraction) Decimal 2 � s Complement Binary Decimal 2 � s Complement Binary 0 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 Examples: 7 - 6 = 7 + (- 6) = 1 3 - 5 = 3 + (- 5) = -2 1 0 1 1 1 0 0 1 1 + 1 0 1 0 + 1 0 1 1 0 0 1 Thursday, January 24, 13

  18. Two’s Complement Arithmetic (Subtraction) Decimal 2 � s Complement Binary Decimal 2 � s Complement Binary 0 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 Examples: 7 - 6 = 7 + (- 6) = 1 3 - 5 = 3 + (- 5) = -2 1 1 0 1 1 1 0 0 1 1 + 1 0 1 0 + 1 0 1 1 0 0 1 Thursday, January 24, 13

  19. Two’s Complement Arithmetic (Subtraction) Decimal 2 � s Complement Binary Decimal 2 � s Complement Binary 0 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 Examples: 7 - 6 = 7 + (- 6) = 1 3 - 5 = 3 + (- 5) = -2 1 1 0 1 1 1 0 0 1 1 + 1 0 1 0 + 1 0 1 1 0 0 0 1 Thursday, January 24, 13

  20. Two’s Complement Arithmetic (Subtraction) Decimal 2 � s Complement Binary Decimal 2 � s Complement Binary 0 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 Examples: 7 - 6 = 7 + (- 6) = 1 3 - 5 = 3 + (- 5) = -2 1 1 0 1 1 1 0 0 1 1 + 1 0 1 0 + 1 0 1 1 0 0 0 1 0 Thursday, January 24, 13

  21. Two’s Complement Arithmetic (Subtraction) Decimal 2 � s Complement Binary Decimal 2 � s Complement Binary 0 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 Examples: 7 - 6 = 7 + (- 6) = 1 3 - 5 = 3 + (- 5) = -2 1 1 1 0 1 1 1 0 0 1 1 + 1 0 1 0 + 1 0 1 1 0 0 0 1 0 Thursday, January 24, 13

  22. Two’s Complement Arithmetic (Subtraction) Decimal 2 � s Complement Binary Decimal 2 � s Complement Binary 0 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 Examples: 7 - 6 = 7 + (- 6) = 1 3 - 5 = 3 + (- 5) = -2 1 1 1 0 1 1 1 0 0 1 1 + 1 0 1 0 + 1 0 1 1 0 0 0 1 1 0 Thursday, January 24, 13

  23. Two’s Complement Arithmetic (Subtraction) Decimal 2 � s Complement Binary Decimal 2 � s Complement Binary 0 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 Examples: 7 - 6 = 7 + (- 6) = 1 3 - 5 = 3 + (- 5) = -2 1 1 1 1 0 1 1 1 0 0 1 1 + 1 0 1 0 + 1 0 1 1 0 0 0 1 1 0 Thursday, January 24, 13

  24. Two’s Complement Arithmetic (Subtraction) Decimal 2 � s Complement Binary Decimal 2 � s Complement Binary 0 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 Examples: 7 - 6 = 7 + (- 6) = 1 3 - 5 = 3 + (- 5) = -2 1 1 1 1 0 1 1 1 0 0 1 1 + 1 0 1 0 + 1 0 1 1 0 0 0 1 1 1 0 Thursday, January 24, 13

  25. Two’s Complement Arithmetic (Subtraction) Decimal 2 � s Complement Binary Decimal 2 � s Complement Binary 0 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 Examples: 7 - 6 = 7 + (- 6) = 1 3 - 5 = 3 + (- 5) = -2 1 1 1 1 0 1 1 1 0 0 1 1 + 1 0 1 0 + 1 0 1 1 0 0 0 1 1 1 1 0 Thursday, January 24, 13

Recommend


More recommend