Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

Similar documents
Chapter 2 Number System

BINARY SYSTEM. Binary system is used in digital systems because it is:

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

EE 109 Unit 6 Binary Arithmetic

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

CHW 261: Logic Design

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

CO Computer Architecture and Programming Languages CAPL. Lecture 9

CS & IT Conversions. Magnitude 10,000 1,

Computer Organization

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

Chapter 10 Binary Arithmetics

DIGITAL ARITHMETIC: OPERATIONS AND CIRCUITS

Number Systems. Both numbers are positive

Part 2,Number Systems Questions

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

Representation of Non Negative Integers

Binary Codes. Dr. Mudathir A. Fagiri

Chapter 3: Arithmetic for Computers

Number Systems Base r

World Inside a Computer is Binary

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

Signed umbers. Sign/Magnitude otation

CHAPTER 2 (b) : AND CODES

Number System. Introduction. Decimal Numbers

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

Digital Fundamentals

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

4/8/17. Admin. Assignment 5 BINARY. David Kauchak CS 52 Spring 2017

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

60-265: Winter ANSWERS Exercise 4 Combinational Circuit Design

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

COMP2611: Computer Organization. Data Representation

Digital Fundamentals. Lab 6 2 s Complement / Digital Calculator

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Chapter 3: part 3 Binary Subtraction

CS101 Lecture 04: Binary Arithmetic

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Computer Number Systems Supplement

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

CS 64 Week 1 Lecture 1. Kyle Dewey

Chapter 1. Digital Systems and Binary Numbers

Arithmetic Operations on Binary Numbers

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Basic Arithmetic (adding and subtracting)

EE292: Fundamentals of ECE

Binary Representations and Arithmetic

Lecture 8: Addition, Multiplication & Division

Harry H. Porter, 2006

Chapter 2 Bits, Data Types, and Operations

Chapter 4. Operations on Data

Module 2: Computer Arithmetic

Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

T02 Tutorial Slides for Week 2

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-2700: Digital Logic Design Winter Notes - Unit 4. hundreds.

COMPUTER ARITHMETIC (Part 1)

Numeric Encodings Prof. James L. Frankel Harvard University

Number Systems. Readings: , Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs

Lecture 6: Signed Numbers & Arithmetic Circuits. BCD (Binary Coded Decimal) Points Addressed in this Lecture

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

CS/EE1012 INTRODUCTION TO COMPUTER ENGINEERING SPRING 2013 HOMEWORK I. Solve all homework and exam problems as shown in class and sample solutions

Computer Sc. & IT. Digital Logic. Computer Sciencee & Information Technology. 20 Rank under AIR 100. Postal Correspondence

Chapter 2 Bits, Data Types, and Operations

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

Lecture 2: Number Systems

INF2270 Spring Philipp Häfliger. Lecture 4: Signed Binaries and Arithmetic

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0

Chapter Three. Arithmetic

11. A Computing Machine

8/27/2016. ECE 120: Introduction to Computing. Graphical Illustration of Modular Arithmetic. Representations Must be Unambiguous

CARLETON UNIVERSITY. Laboratory 2.0

Logic Circuits I ECE 1411 Thursday 4:45pm-7:20pm. Nathan Pihlstrom.

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-278: Digital Logic Design Fall Notes - Unit 4. hundreds.

Lecture 3: Binary Subtraction, Switching Algebra, Gates, and Algebraic Expressions

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.


COMP 122/L Lecture 2. Kyle Dewey

CO212 Lecture 10: Arithmetic & Logical Unit

Chapter 2 Bits, Data Types, and Operations

*Instruction Matters: Purdue Academic Course Transformation. Introduction to Digital System Design. Module 4 Arithmetic and Computer Logic Circuits

Lecture (02) Operations on numbering systems

Chapter 4 Arithmetic Functions

Signed Binary Numbers

unused unused unused unused unused unused

Fundamentals of Programming Session 2

Arithmetic Processing

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997

MC1601 Computer Organization

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

Introduction to Computers and Programming. Numeric Values

Chapter 1 Review of Number Systems

SE311: Design of Digital Systems

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION

Arithmetic for Computers

Chapter 5: Computer Arithmetic

ECE/Comp Sci 352 Digital Systems Fundamentals. Charles R. Kime Section 2 Fall Logic and Computer Design Fundamentals

Transcription:

Digital Arithmetic Digital Arithmetic: Operations and Circuits Dr. Farahmand

Binary Arithmetic Digital circuits are frequently used for arithmetic operations Fundamental arithmetic operations on binary numbers and digital circuits which perform arithmetic operations will be examined. Binary numbers are added like decimal numbers. In decimal, when numbers sum more than 9 a carry results. In binary when numbers sum more than 1 a carry takes place. Addition is the basic arithmetic operation used by digital devices to perform subtraction, multiplication, and division. If the numbers are unsigned and positive add them as follow: 1 + 0 = 1 with carry of 0 1 + 1 = 0 with carry of 1 1 + 1 + 1 = 1 with carry of 1 For example: 011.011 + 010.110 = 110.001 = 6.125 base 10

Adding Unsigned Numbers Examples: X 190 10111110 Y 141 10001101 X+Y 331 101001011 X 127 1111111 Y 63 111111 X+Y 190 10111110 X 170 10101010 Y 85 1010101 X+Y 255 11111111

Adding Unsigned Numbers Examples: X 190 10111110 Y 141 10001101 X+Y 331 101001011 X 127 1111111 Y 63 111111 X+Y 190 10111110 X 170 10101010 Y 85 1010101 X+Y 255 11111111

Representing Signed Numbers Since it is only possible to show magnitude with a binary number, the sign (+ or -) is shown by adding an extra sign bit. A sign bit of 0 indicates a positive number. A sign bit of 1 indicates a negative number. The 2 s complement system is the most commonly used way to represent signed numbers. +7 0-1 -7-8 0 1 1 1 0 0 0 0 1 1 1 1 1 0 0 1 1 0 0 0 Sign-bit Magnitude bits Examples of 2 s complement representation -8-2^3 +4 +2^2 +2 +1 +2^1 +2^0

Representing Signed Numbers Converting to 2 s Complement In order to change a binary number to 2 s complement it must first be changed to 1 s complement. To convert to 1 s complement, simply change each bit to its complement (opposite). To convert 1 s complement to 2 s complement add 1 to the 1 s complement. A positive number is true binary with 0 in the sign bit. A negative number is in 2 s complement form with 1 in the sign bit. A binary number can be negated by taking the 2 s complement of it. For example: +9 01001 (sign bit = 0, indicating +) 2 s complement of 9 01001 10110 10110 + 1 10111 = -9 This is The sign BIT When the sign-bit is zero Positive number If the sign-bit is set Negative number Remember: 2 s complement is just a conventional way of representing signed numbers in digital arithmetic Don t ask why!

2 s Complement Representation Assuming N+1 bits representing a 2 s Complement (that is representing the number with N bits and one bit is dedicated to indicate the sign): Largest positive number will be 2 N -1 Smallest signed number (largest negative number) will be -2 N Total numbers (including zero) that can be represented will be 2 N+1 For example: Assume 3+1 bits Largest pos. number will be 0111= +7 Smallest number will be 1000 = -8 Remember: 1111= -1 Zero is represented by 0000 = Zero For example: Assume 6+1 bits Largest pos. number will be?? Smallest signed number will be?? Zero is represented by?? 0 111 111 = 63 1 000 000 = -64 0 000 000 = 0

More Examples Integer 2's Complement Signed 7 0111 6 0110 5 0101 4 0100 3 0011 2 0010 1 0001 0 0000-1 1111-2 1110-3 1101-4 1100-5 1011-6 1010-7 1001-8 1000 Signed Integer Unsigned 2's Complement 5 5 0000 0101 4 4 0000 0100 3 3 0000 0011 2 2 0000 0010 1 1 0000 0001 0 0 0000 0000-1 255 1111 1111-2 254 1111 1110-3 253 1111 1101-4 252 1111 1100-5 251 1111 1011 Remember: Always know how many bits are provided!

2 s Complement Representation Integer Signed 2's Complement 7 0111 6 0110 5 0101 4 0100 3 0011 2 0010 1 0001 0 0000-1 1111-2 1110-3 1101-4 1100-5 1011-6 1010-7 1001-8 1000

Arithmetic Operations using 2 s Complement Inverting A positive number to a negative number A negative number to a positive number Either case just take the 2 s complement Adding A and B A+B (assuming N bits represent the magnitude and one bit is dedicated as the sign-bit) Subtracting B from A A-B Just take the 2 s Complement of B Add A and B (A+B) Magnitude Overflow: (max unsigned number that can be represented using 8 bits is 255) The carry will be ignored Note the value is negative X 180 10110100 Y 85 01010101 X+Y 265 100001001 X 6 0110 Y -3 1101 X-Y 3 1 0011 X 4 0100 Y -7 1001 X-Y -3 1101 Overflow: (max signed number that can be represented using 4 bits is -8) X -3 1101 Y -6 1010 X+Y -9 1 0111 Overflow: (max signed number that can be represented using 4 bits is 7) X 7 0 111 Y 7 0 111 X+Y 14 1 110

Arithmetic Operations using 2 s Complement Inverting A positive number to a negative number A negative number to a positive number Either case just take the 2 s complement Adding A and B A+B (assuming N bits represent the magnitude and one bit is dedicated as the sign-bit) Subtracting B from A A-B Just take the 2 s Complement of B Add A and B (A+B) NOTE: When a Positive and a Negative number are added together, the overflow will be a signed overflow and it is ok! The overflow can be discarded when it is sign overflow (max = -16): X -4 11100 Y -9 10111 X+Y -13 1 10011 Magnitude Overflow: (max unsigned number that can be represented using 8 bits is 255) The carry will be ignored Note the value is negative Overflow: (max signed number that can be represented using 4 bits is -8) Overflow: (max signed number that can be represented using 4 bits is 7) X 180 10110100 Y 85 01010101 X+Y 265 100001001 X 6 0110 Y -3 1101 X-Y 3 1 0011 X 4 0100 Y -7 1001 X-Y -3 1101 X -3 1101 Y -6 1010 X+Y -9 1 0111 X 7 0 111 Y 7 0 111 X+Y 14 1 110

BCD Addition BDC numbers They are between 0 and 9 Hence each decimal number is represented by 4 bits Add each number between 0-9 individually 0 1 1 0 BCD for 6 0 1 1 1 BCD for 7 1 1 0 1 13 but invalid! 0 1 1 0 Add 6 to correct 0 0 0 1 0 0 1 1 BDC for 13!!

BCD Addition Another Example BDC numbers They are between 0 and 9 Hence each decimal number is represented by 4 bits Add each number between 0-9 individually 1 0 1 0 1 1 0 0 1 BCD for 59 0 0 1 1 1 0 0 0 BCD for 38 1 0 0 1 0 0 0 1 91 but invalid! 0 1 1 0 Add 6 1 0 0 1 0 1 1 1 BDC for 97!!

Hex Arithmetic Addition of Hex numbers is similar to decimal addition Remember the largest value is 16 (F) and NOT 9! Carry a 1 if the number is larger than F Use the following steps Add the hex digits in decimal. If the sum is 15 or less express it directly in hex digits. If the sum is greater than 15, subtract 16 and carry 1 to the next position. 9 + 8 In Hex=11 3AF + 23C = 5EB 8+B=8+(11)= 1919-16=3, Carry 1 9 + 8 In Decimal =17 17-16 =1 In Hex = 11 16 58 + 4B = A3

Hex Arithmetic Subtraction of hex numbers follows a similar method as binary numbers Make sure you take the 2 s complement of the negative hex number Method 1: Method 2: Subtract the number from FFFF Write the results in hex Add one to the final answer For example: 2 s complement of 3A5 is: FFF-3A5=C5A C5A+1 = C5B 592-3A5 592 + C5B = 11ED 67F - 2A4 67F + D5C = 3DB Convert the number to Binary Take the 2 s complement Convert back the results into hex value Simply add the values together 5+C=2+(12)= 1717-16=1, Carry 1 Must be discarded! FFF- 3A5= (15-3),(15-10),(15-5) = 12, 5, 10 C5A+1=C5B F+C=(15)+(12)=2 727-16=11 or B, Carry 1