cpsc 121 models of computation
play

CPSC 121: Models of Computation Module 3: Representing Values in a - PowerPoint PPT Presentation

CPSC 121: Models of Computation Module 3: Representing Values in a Computer Module 3: Coming up... Pre-class quiz #4 is due Wednesday September 30 th at 19:00. Assigned reading for the quiz: Epp, 4 th edition: 2.3 Epp, 3 rd edition: 1.3 Rosen, 6


  1. CPSC 121: Models of Computation Module 3: Representing Values in a Computer

  2. Module 3: Coming up... Pre-class quiz #4 is due Wednesday September 30 th at 19:00. Assigned reading for the quiz: Epp, 4 th edition: 2.3 Epp, 3 rd edition: 1.3 Rosen, 6 th edition: 1.5 up to the bottom of page 69. Rosen, 7 th edition: 1.6 up to the bottom of page 75. CPSC 121 – 2020W T1 2

  3. Module 3: Coming up... Pre-class quiz #5 is tentatively due Monday October 5 th at 19:00. Assigned reading for the quiz: Epp, 4 th edition: 3.1, 3.3 Epp, 3 rd edition: 2.1, 2.3 Rosen, 6 th edition: 1.3, 1.4 Rosen, 7 th edition: 1.4, 1.5 CPSC 121 – 2020W T1 3

  4. Module 3: Representing Values By the start of this class you should be able to Convert unsigned integers from decimal to binary and back. Take two's complement of a binary integer. Convert signed integers from decimal to binary and back. Convert integers from binary to hexadecimal and back. Add two binary integers. CPSC 121 – 2020W T1 4

  5. Module 3: Representing Values Quiz 3 feedback: Well done overall. Only one question had an average below 90%: What is the decimal value of the signed 6-bit binary number 101110? Answer: CPSC 121 – 2020W T1 5

  6. Module 3: Representing Values Quiz 3 feedback: Can one be 1/3rd Scottish? We will get back to this question (c) ITV/Rex Features later. I don't have any Scottish ancestors. So we will ask if one can be 1/3 Belgian instead (which would you prefer: a bagpipe and a kilt, or belgian chocolate?) (c) 1979, Dargaud ed. et Albert Uderzo CPSC 121 – 2020W T1 6

  7. Module 3: Representing Values ? ? ? CPSC 121: the BIG questions: ? ? We will make progress on two of them: How does the computer (e.g. Dr. Racket) decide if ? ? the characters of your program represent a name, a ? ? number, or something else? How does it figure out if ? you have mismatched " " or ( )? How can we build a computer that is able to ? execute a user-defined program? ? ? ? ? ? ? CPSC 121 – 2020W T1 7

  8. Module 3: Representing Values By the end of this module, you should be able to: Critique the choice of a digital representation scheme, including describing its strengths, weaknesses, and flaws (such as imprecise representation or overflow), for a given type of data and purpose, such as fixed-width binary numbers using a two’s complement scheme for signed integer arithmetic in computers hexadecimal for human inspection of raw binary data. CPSC 121 – 2020W T1 8

  9. Module 3: Representing Values Motivating examples: Understand and avoid cases like those at: http://www.ima.umn.edu/~arnold/455.f96/disasters.html Death of 28 people caused by failure of an anti-missile system, caused in turn by the misuse of one representation for fractions. Explosion of a $500 million space vehicle caused by failure of the guidance system, caused in turn by misuse of a 16 bit signed binary value. We will discuss both of the representations that caused these catastrophes. CPSC 121 – 2020W T1 9

  10. Module 3: Representing Values Summary Unsigned and signed binary integers. Modular arithmetic. Characters. Real numbers. Hexadecimal. CPSC 121 – 2020W T1 10

  11. Module 3.1: Unsigned and signed binary integers Notice the similarities: Number b 3 b 2 b 1 b 0 Number a b c d 0 F F F F 0 0 0 0 0 1 F F F T 1 0 0 0 1 2 F F T F 2 0 0 1 0 3 F F T T 3 0 0 1 1 4 F T F F 4 0 1 0 0 5 F T F T 5 0 1 0 1 6 F T T F 6 0 1 1 0 7 F T T T 7 0 1 1 1 8 T F F F 8 1 0 0 0 9 T F F T 9 1 0 0 1 CPSC 121 – 2020W T1 11

  12. Module 3.1: Unsigned and signed binary integers Definitions: An unsigned integer is one we have decided will only represent integer values that are 0 or larger. A signed integer is one we have decided can represent either a positive value or a negative one. A sequence of bits is intrinsically neither signed nor unsigned (nor anything else). it's us who give it its meaning. CPSC 121 – 2020W T1 12

  13. Module 3.1: Unsigned and signed binary integers Unsigned integers review: the binary value b n − 1 b n − 2 ... b 2 b 1 b 0 represents the integer n − 1 + b n − 2 2 n − 2 + ... + b 2 2 2 + b 1 2 1 + b 0 b n − 1 2 or written differently n − 1 b i 2 i ∑ i = 0 We normally use base 10 instead of 2, but we could use 24 [clocks!] or 13 (maybe…) or any other value. CPSC 121 – 2020W T1 13

  14. Module 3.1: Unsigned and signed binary integers “Magic” formula to negate a signed integer: Replace every 0 bit by a 1, and every 1 bit by a 0. Add 1 to the result. This is called two's complement. Why does it make sense to negate a signed binary integer this way? CPSC 121 – 2020W T1 14

  15. Module 3.1: Unsigned and signed binary integers F or 3-bit integers, what is 111 + 1? Hint: think of a 24 hour clock. a) 110 b) 111 c) 1000 d) 000 e) Error: we can not add these two values. ▷ CPSC 121 – 2020W T1 15

  16. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. 0 000 CPSC 121 – 2020W T1 17

  17. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. 0 1 000 001 CPSC 121 – 2020W T1 18

  18. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. 0 1 2 000 001 010 CPSC 121 – 2020W T1 19

  19. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. 0 1 2 3 000 001 010 011 CPSC 121 – 2020W T1 20

  20. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. 0 1 2 3 4 000 001 010 011 100 CPSC 121 – 2020W T1 21

  21. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. 0 1 2 3 4 5 000 001 010 011 100 101 CPSC 121 – 2020W T1 22

  22. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. 0 1 2 3 4 5 6 000 001 010 011 100 101 110 CPSC 121 – 2020W T1 23

  23. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. 0 1 2 3 4 5 6 7 000 001 010 011 100 101 110 111 CPSC 121 – 2020W T1 24

  24. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. 0 1 2 3 4 5 6 7 8 000 001 010 011 100 101 110 111 000 CPSC 121 – 2020W T1 25

  25. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. 0 1 2 3 4 5 6 7 8 9 000 001 010 011 100 101 110 111 000 001 CPSC 121 – 2020W T1 26

  26. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. 0 1 2 3 4 5 6 7 8 9 10 000 001 010 011 100 101 110 111 000 001 010 CPSC 121 – 2020W T1 27

  27. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. 0 1 2 3 4 5 6 7 8 9 10 11 000 001 010 011 100 101 110 111 000 001 010 011 CPSC 121 – 2020W T1 28

  28. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. now let’s add the binary representation for zero to minus eight. 0 1 2 3 4 5 6 7 8 9 10 11 000 001 010 011 100 101 110 111 000 001 010 011 CPSC 121 – 2020W T1 29

  29. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. now let’s add the binary representation for zero to minus eight. -1 0 1 2 3 4 5 6 7 8 9 10 11 111 000 001 010 011 100 101 110 111 000 001 010 011 CPSC 121 – 2020W T1 30

  30. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. now let’s add the binary representation for zero to minus eight. -1 0 1 2 3 4 5 6 7 8 9 10 11 -2 110 111 000 001 010 011 100 101 110 111 000 001 010 011 CPSC 121 – 2020W T1 31

  31. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. now let’s add the binary representation for zero to minus eight. -1 0 1 2 3 4 5 6 7 8 9 10 11 -3 -2 101 110 111 000 001 010 011 100 101 110 111 000 001 010 011 CPSC 121 – 2020W T1 32

  32. Module 3.1: Unsigned and signed binary integers Using 3 bits to represent integers let us write the binary representations for zero to eleven. now let’s add the binary representation for zero to minus eight. -4 -1 0 1 2 3 4 5 6 7 8 9 10 11 -3 -2 100 101 110 111 000 001 010 011 100 101 110 111 000 001 010 011 CPSC 121 – 2020W T1 33

Recommend


More recommend