lect04_s.pdf - Discrete Mathematics for Computing MAT1101...

This preview shows page 1 - 12 out of 144 pages.

Discrete Mathematics for Computing MAT1101 Logic School of Agricultural, Computational and Environmental Sciences Faculty of Health, Engineering and Sciences Lecture 4 MAT1101 1
Lecture Summary 1 Integer arithmetic 2 Real numbers (Floating Point Numbers) 3 IEEE and floating point numbers Implications of truncation Range Underflow/Overflow 4 Introduction to logic Propositions Connectives Basic truth tables Inverse, converse and contrapositive 5 Laws of logic MAT1101 2
Integer arithmetic on 4-bit computer Integer Computer Integer Stored Value Value -8 1000 0 0000 -7 1001 1 0001 -6 1010 2 0010 -5 1011 3 0011 -4 1100 4 0100 -3 1101 5 0101 -2 1110 6 0110 -1 1111 7 0111 Negative numbers all start with a 1 . The sign bit is 1 and has a place value of 8 in a 4-bit number. Hence, the 4-bit representation of the number is 𝑛 + 16 . Example: −4 computer representation is 1100 2 = 12 10 MAT1101 3
Integer arithmetic on 4-bit computer Integer Computer Integer Stored Value Value -8 1000 0 0000 -7 1001 1 0001 -6 1010 2 0010 -5 1011 3 0011 -4 1100 4 0100 -3 1101 5 0101 -2 1110 6 0110 -1 1111 7 0111 Positive numbers all start with a 0 . Hence, the 4-bit representation of the number is 0𝑏𝑏𝑏 2 . Example: 4 computer representation is 0100 2 MAT1101 4
Integer arithmetic on 4-bit computer Integer Computer Integer Stored Value Value -8 1000 0 0000 -7 1001 1 0001 -6 1010 2 0010 -5 1011 3 0011 -4 1100 4 0100 -3 1101 5 0101 -2 1110 6 0110 -1 1111 7 0111 Suppose we add two integers. What do you notice? MAT1101 5
Integer arithmetic on 4-bit computer Integer Computer Integer Stored Value Value -8 1000 0 0000 -7 1001 1 0001 -6 1010 2 0010 -5 1011 3 0011 -4 1100 4 0100 -3 1101 5 0101 -2 1110 6 0110 -1 1111 7 0111 Suppose we add two integers. What do you notice? Consider 6 + 7 . Can we store it? MAT1101 5
Integer arithmetic on 4-bit computer Integer Computer Integer Stored Value Value -8 1000 0 0000 -7 1001 1 0001 -6 1010 2 0010 -5 1011 3 0011 -4 1100 4 0100 -3 1101 5 0101 -2 1110 6 0110 -1 1111 7 0111 Suppose we add two integers. What do you notice? Consider 6 + 7 . Can we store it? NO, too large. However, if we restrict ourselves to numbers which can be stored after the addition, the addition can be done by: Simple adding the two binary numbers in the usual way. Except is a 1 arises in the fifth column (i.e. 5 digits) it is ignored. MAT1101 5
Integer arithmetic on 4-bit computer Integer Computer Integer Stored Value Value -8 1000 0 0000 -7 1001 1 0001 -6 1010 2 0010 -5 1011 3 0011 -4 1100 4 0100 -3 1101 5 0101 -2 1110 6 0110 -1 1111 7 0111 Example 1 2+3 0010 0011 0101 5 2 -4+7 1100 0111 10011 3 3 6+7 0110 0111 1101 -3 which is out by 16 MAT1101 6
Why does this work? An integer in this computer is either 16 more or the integer itself. Therefore the result either exceeds what it should by 16 or 32. Ignoring the fifth column is equivalent to −16 . If the answer is not correct it must only differ in this computer by a multiple of 16. The problem with adding 6 + 7 is called an overflow . Easy detected as adding two positive integers should not give a negative result. Similarly, adding to ve integers should not give a positive result. MAT1101 7
Real numbers We need to store very large and very small numbers. Scientific notation. Mass of Earth 5976000000000000000000000 kg 5.976 × 10 24 kg Radius of an atom 0.0000000000000012 m 1.2 × 10 −15 m MAT1101 8
Normalised notation In normalised notation we have: 𝑚 × 10 𝑒 , where 0.1 ≤ 𝑚 < 1 , 10 is the base and 𝑒 is the power. 𝑚 is called the mantissa ( significand ). Example Mass of Earth 0.5976 × 10 25 kg Radius of an atom 0.12 × 10 −14 m MAT1101 9

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture