Download presentation

Presentation is loading. Please wait.

Published byMichael Warren Modified over 2 years ago

1
15 October 2013Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems Autumn 2013 Week 3a: Number Representations

2
Recap: Programs A program is a sequence of instructions. The instructions may refer to memory cells which store values such as integers. In Toms computer the memory cells are the boxes. Each memory cell has an address and contents. 15 October 2013Birkbeck College, U. London2

3
Recap: Running a Program The instructions of the program are executed one by one. When an instruction is executed, the values in the memory cells may change. When the program halts the output is usually the values of one or more memory cells. 15 October 2013Birkbeck College, U. London3

4
Recap: Variables Here is a typical statement in a programming language: q=0; Left hand side: the name q of a variable Right hand side: an expression Execution: evaluate the right hand side to obtain a number. Store the number in a box named q. 15 October 2013Birkbeck College, U. London4

5
15 October 2013Birkbeck College, U. London5 Exercise from Week 2 Sketch an algorithm that takes as input a strictly positive integer n and outputs an integer k such that

6
15 October 2013Brookshear, Section 1.66 Representations of Negative Integers Put a minus sign in front of the representation for a positive integer. Excess notation. Twos Complement notation – the most popular representation for negative integers in computers.

7
15 October 2013Brookshear, Section 1.67 Excess Notation Problem: represent a set of positive and negative integers using bit strings with a fixed length n. Represent 0 by 10…0 (n bits). Represent positive numbers by counting up from 10…0 in standard binary notation. Represent negative integers by counting down from 10…0 in standard binary notation.

8
15 October 2013Brookshear, Section 1.68 Example of Excess Notation n=

9
Examples Find the 6 bit excess notation for the decimal numbers 7 and -6. Which decimal number has the 5 bit excess notation October 2013Birkbeck College, U. London9

10
15 October 2013Birkbeck College, U. London10 Twos Complement Notation Form the bit string 10…0 with n+1 bits. Represent 0 by the last n bits of 10…0. Represent positive integers by counting up from 10…0 in standard binary notation and using the last n bits. Represent negative integers by counting down from 10…0 in standard binary notation and using the last n bits.

11
15 October 2013Brookshear, Section Example of Twos Complement Notation n=4 The left most bit indicates the sign.

12
15 October 2013Brookshear, Section Addition and Subtraction In the twos complement system subtraction reduces to addition. E.g. to evaluate 6-5 in 4 bit twos complement notation, add the tc bit strings for 6 and –5, then take the four rightmost bits === ==

13
15 October 2013Brookshear, Section Explanation The bit strings for TC[6] and TC[-5] are the rightmost four bits of Binary[2 4 +6] and Binary[2 4 -5], respectively. The bit strings TC[6], TC[-5] are added as if they were binary numbers. The rightmost four bits of the result equal the rightmost four bits of Binary[(2 4 +6)+(2 4 -5)]= Binary[ ]. The right most four bits of Binary[ ] are the bit string for TC[1].

14
Why Use Twos Complement Addition and subtraction require one circuit for addition and one circuit for negation. This is more efficient than having a circuit for addition and a circuit for subtraction. 15 October 2013Brookshear, Section 1.614

15
15 October 2013Brookshear, Section Twos Complement Notation for m and -m Suppose TC[m] = s || 1 || t, where t is a string of zeros. Then TC[-m]=Complement[s]||1||t. Proof: the rightmost n bits of TC[m]+TC[-m] are all zero. Example: n=4, TC[3]=0011, TC[-3]=1101.

16
15 October 2013Birkbeck College, U. London16 Example Find the 5 bit twos complement representations for the decimal integers 5 and -5.

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google