Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.

Slides:



Advertisements
Similar presentations
Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
Advertisements

©Brooks/Cole, 2003 Chapter 4 Operations on Bits. ©Brooks/Cole, 2003 Apply arithmetic operations on bits when the integer is represented in two’s complement.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
King Fahd University of Petroleum and Minerals
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Assembly Language and Computer Architecture Using C++ and Java
Level ISA3: Information Representation
Assembly Language and Computer Architecture Using C++ and Java
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Chapter Chapter Goals Know the different types of numbers Describe positional notation.
ECE 331 – Digital System Design
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
COE 308: Computer Architecture (T041) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (Appendix A, Computer Architecture: A Quantitative Approach,
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Mantıksal Tasarım – BBM231 M. Önder Efe
Dr. Bernard Chen Ph.D. University of Central Arkansas
Data Representation Number Systems.
Simple Data Type Representation and conversion of numbers
ES 244: Digital Logic Design Chapter 1 Chapter 1: Introduction Uchechukwu Ofoegbu Temple University.
Numbering systems.
Copyright © Cengage Learning. All rights reserved. CHAPTER 2 THE LOGIC OF COMPOUND STATEMENTS THE LOGIC OF COMPOUND STATEMENTS.
Data Representation – Binary Numbers
Numbering Systems CS208.
Logic and Digital System Design - CS 303
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
Chapter 2 Number Systems + Codes. Overview Objective: To use positional number systems To convert decimals to binary integers To convert binary integers.
Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.
Logic Design Dr. Yosry A. Azzam. Binary systems Chapter 1.
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
IT101: INFORMATION TECHNOLOGY FUNDAMENTALS 1 Edited By Dr. Ahmed Abo-Bakr Information Technology Dept. Faculty of Computers & Information.
1 CS103 Guest Lecture Number Systems & Conversion Bitwise Logic Operations.
Chapter 2 Binary Values and Number Systems. 2 2 Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645,
Computer Systems Architecture Copyright © Genetic Computer School 2008 CSA 1- 0 Lesson 1 Number System.
Fixed and Floating Point Numbers Lesson 3 Ioan Despi.
Topic 1 – Number Systems. What is a Number System? A number system consists of an ordered set of symbols (digits) with relations defined for addition,
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
AEEE2031 Data Representation and Numbering Systems.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
WEEK #2 NUMBER SYSTEMS, OPERATION & CODES (PART 1)
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1, * *10 + 4*1 n Alternate view: Digit position.
Chapter 1: Binary Systems
ECE 3110: Introduction to Digital Systems Number Systems.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
ECE 2110: Introduction to Digital Systems
Integer Operations Computer Organization and Assembly Language: Module 5.
Chapter 8 Computer Arithmetic. 8.1 Unsigned Notation Non-negative notation  It treats every number as either zero or a positive value  Range: 0 to 2.
Chapter 4 Operations on Bits. Apply arithmetic operations on bits when the integer is represented in two’s complement. Apply logical operations on bits.
ECE 2110: Introduction to Digital Systems Number Systems: conversions.
BINARY SYSTEMS ENGR. KASHIF SHAHZAD 1. BINARY NUMBERS 1/2 Internally, information in digital systems is of binary form groups of bits (i.e. binary numbers)
S 2/e C D A Computer Systems Design and Architecture Second Edition© 2004 Prentice Hall Chapter 6 Overview Number Systems and Radix Conversion Fixed point.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
ECE 2110: Introduction to Digital Systems Number Systems: conversions.
Week 1(Number System) Muhammad Ammad uddin Logic Design Lab I (CEN211)
Binary & Hex Review.
Number Systems & Binary Arithmetic
Chapter 4 Operations on Bits.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
IT 0213: INTRODUCTION TO COMPUTER ARCHITECTURE
Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1.
Digital Electronics and Microprocessors
Chapter 2: Number Systems
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Presentation transcript:

Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi

Digital Number Systems Digital number systems have a base or radix b Using positional notation, an m-digit base b number is written x = x m-1 x m-2... x 1 x 0 0  x i  b-1, 0  i < m The value of this unsigned integer is

Range of Unsigned m Digit Base b Numbers The largest number has all of its digits equal to b-1, the largest possible base b digit Its value can be calculated in closed form An important summation—geometric series

Number Systems base 10 (decimal) 10 digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 positional notation 1011 ten = 1 x x x x 10 0 base 2 (binary) 2 digits 0, two = 1 x x x x two = 11 ten

Number Systems base 8 (octal) 8 digits 0, 1, 2, 3, 4, 5, 6, eight = 1 x x x x eight = 521 ten base 16 (hexadecimal) 16 digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F 1001 sixteen = 1 x x x x sixteen = 4113 ten

Number Systems: 2 The digital logic of computers: simple, reliable circuits (AND, OR and NOT gates) that “lock” one of two states (On / Off, True / False, 0 / 1) To represent numbers, a single binary digit (bit) can represent 2 possible numbers (0 or 1). We can add more bits to the number giving the additional bits a place value, just as we do for decimal numbers (base 10). Each additional bit doubles the number of possible combinations:

To convert a binary number to decimal, one just adds up the place values of the 1-bits, as follows : Bit position Binary number You can try with The number has 8 bits I numbered starting with 0 on the right--> the place value of each bit is 2 to the power of the bit number EX: 2 to the 7th = 128

A story: Seven computer scientists went for a walk. After a while they counted themselves: 0, 1, 2, 3, 4, 5, 6. One must be missing! So they spent the rest of the day looking, but never figured out where the 7th one could have gone. This is known as an “off by one” error. It is all too common.

To convert from decimal to binary: divide by 2 repeatedly until 0 is reached then the remainders, reading up, are the binary number 221 /2 = 110 r = / 2 = 55r = 0 55 / 2 = 27r = 1 27 / 2 = 13r = 1 13 / 2 = 6r = 1 6 / 2 = 3r = 0 3 / 2 = 1 r = 1 1 / 2 = 0 r = 1 Answer:

Radix Conversion: General Matters Converting from one number system to another involves computation We call the base in which calculation is done c and the other base b Calculation is based on the division algorithm — For integers a and b, there exist integers q and r such that a = q  b + r, with 0  r  b-1 Notation: q =  a/b  r = a mod b

Digit Symbol Correspondence Between Bases Each base has b (or c) different symbols to represent the digits If b < c, there is a table of b + 1 entries giving base c symbols for each base b symbol and b If the same symbol is used for the first b base c digits as for the base b digits, the table is implicit If c < b, there is a table of b + 1 entries giving a base c number for each base b symbol and b For base b digits  c, the base c numbers have more than one digit Base 12: A B 10 Base 3:

Convert Base b Integer to Calculator’s Base, c 1) Start with base b x = x m-1 x m-2... x 1 x 0 2) Set x = 0 in base c 3) Left to right, get next symbol x i 4) Lookup base c number D i for symbol x i 5) Calculate in base c: x = x  b + D i 6) If there are more digits, repeat from step 3 Example: convert 3AF 16 to base 10 x = 0 x = 16 x + 3 = 3 x = 16  (= A) = 58 x  16  (= F) = 943

Convert Calculator’s Base Integer to Base b 1) Let x be the base c integer 2) Initialize i = 0 and v = x & get digits right to left 3) Set D i = v mod b & v =  v/b . Lookup D i to get x i 4) i = i + 1; If v  0, repeat from step 3 Example: convert to base  12 = 298 (rem = 11)  x 0 = B 298  12 = 24 (rem = 10)  x 1 = A 24  12 = 2 (rem = 0)  x 2 = 0 2  12 = 0 (rem = 2)  x 3 = 2 Thus = 20AB 12

Negative Numbers need a representation for negative numbers use two’s complement binary number negated as follows starting from rightmost bit and working left, copy up to and including the first 1-bit; thereafter, write 1-bits for 0-bits and 0-bits for 1-bits. example in 16-bit word

Complement Number Systems Complement number systems use unsigned numbers to represent both positive and negative numbers Recall that the range of an m digit base b unsigned number is 0  x  b m -1 The first half of the range is used for positive, and the second half for negative, numbers Positive numbers are simply represented by the unsigned number corresponding to their absolute value

Complement Operations for m-Digit Base b Numbers Radix complement of m-digit base b number x x c = (b m - x) mod b m Diminished radix complement of x x c = b m x The complement of a number in the range 0  x  b m -1 is in the same range The mod b m in the radix complement definition makes this true for x = 0; it has no effect for any other value of x Specifically, the radix complement of 0 is 0

Complement Representations of Negative Numbers For even b, radix complement system represents one more negative than positive value While diminished radix complement system has 2 zeros but represents same number of positive & negative values Radix ComplementDiminished Radix Complement Number Representation 0000 or b m -1 0<x<b m /2x x -b m /2  x<0 |x| c = b m - |x| |x| c = b m |x| -b m /2<x<0

Base 2 Complement Representations In 1’s complement, 255 = is often called -0 In 2’s complement, -128 = is a legal value, but trying to negate it gives overflow 8 Bit 2’s Complement8 Bit 1’s Complement Number Representation or 255 0<x<128x x -128  x< |x| |x| -127  x<0

Digitwise Computation of the Diminished Radix Complement Using the geometric series formula, the b-1’s complement of x can be written If 0  x i  b-1, then 0  (b-1-x i )  b-1, so last formula is just an m-digit base b number with each digit obtained from the corresponding digit of x

Conversion Between Related Bases by Digit Grouping Let base b = c k ; for example b = c 2 Then base b number x 1 x 0 is base c number y 3 y 2 y 1 y 0, where x 1 base b = y 3 y 2 base c and x 0 base b = y 1 y 0 base c Examples: = = 49C 16 49C 16 = = = =

Addition and Subtraction addition bits are added and carry propagated leftwards ten ten = ten subtraction use negation and addition i.e. x - y = x + (-y) ten ten (2’s complement) = (1) ten

Addition and Subtraction Addition (and subtraction) of binary numbers is similar to ordinary addition. If the sum won’t fit in one bit, you need to carry one to the next place on the left. The rules are: = = = = 0 and a carry (from a previous carry) = 1 and a carry

Examples: (the second illustrates a “ripple effect”) Long binary numbers get hard for humans to read: , etc… and it takes a long time to convert them into decimal ===> we need a more readable representation: Bases 8, 16

Carry and Overflow need to take account of restricted word size carry : when unsigned numbers are added, a carry occurs when a carry is propagated from the leftmost bit ten ten = (1) ten (256) overflow : when signed numbers are added, a overflow occurs when the carry into the sign bit differs from the carry out of it ten ten ten

Multiplication algorithm operates on two unsigned n-bit numbers, a and b initialisation load a into multiplier register A load b into multiplier register B clear register P repeat n times 1. if rightmost bit of A is 1-bit, then add B to P 2. shift P and A right, with rightmost bit of P shifting into leftmost bit of A product is in P and A

Multiplication Example a =5, b = 3 P: 0000 A: 0101 B: 0011 Iteration 1 P: 0001  A: 1010 B: 0011 Iteration 2 P: 0000  A: 1101 B: 0011 Iteration 3 P: 0001  A: 1110 B: 0011 Iteration 4 P: 0000  A: 1111 B: 0011 product in PA : answer = 15

Division algorithm operates on two unsigned n-bit numbers, a and b initialisation load a into divider register A, load b into divider register B clear register P repeat n times 1. shift P and A left, with leftmost bit of A shifting into rightmost bit of P 2. subtract B from P 3. if result of subtraction is negative, set rightmost bit of A to 0-bit, otherwise set to 1-bit and add B to P restoring its value quotient in A, remainder in P

Division example, a = 14, b = 3 P: 0000 A: 1110 B: 0011 Iteration 1 P: 0001  A: 1100 B: 0011 Iteration 2 P: 0000  A: 1001 B: 0011 Iteration 3 P: 0001  A: 0010 B: 0011 Iteration 4 P: 0010  A: 0100 B: 0011 quotient in A = 4 remainder in P = 2