Computer Engineering (Logic Circuits) Dr. Tamer Samy Gaafar Lec. # 2

Slides:



Advertisements
Similar presentations
HEXADECIMAL NUMBERS Code
Advertisements

Addition and Subtraction. Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement.
ELEC353 S. al Zahir UBC Sign-Magnitude Representation High order bit is sign: 0 = positive (or zero), 1 = negative Low order bits represent the magnitude:
Forging new generations of engineers. Binary Addition & Subtraction.
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
ECE 331 – Digital System Design
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Assembly Language and Computer Architecture Using C++ and Java
Signed Numbers.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
9/15/09 - L15 Decoders, Multiplexers Copyright Joanne DeGroat, ECE, OSU1 Binary additon & subtraction.
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
3. Representing Integer Data
1.6 Signed Binary Numbers.
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Chapter 7 Arithmetic Operations and Circuits Binary Arithmetic Addition –When the sum exceeds 1, carry a 1 over to the next-more-significant column.
BINARY ARITHMETIC Binary arithmetic is essential in all digital computers and in many other types of digital systems.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
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.
CSE 241 Computer Organization Lecture # 9 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
1 DLD Lecture 18 Recap. 2 Recap °Number System/Inter-conversion, Complements °Boolean Algebra °More Logic Functions: NAND, NOR, XOR °Minimization with.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
ECE 331 – Digital System Design Representation and Binary Arithmetic of Negative Numbers and Binary Codes (Lecture #10) The slides included herein were.
AEEE2031 Data Representation and Numbering Systems.
ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
WEEK #2 NUMBER SYSTEMS, OPERATION & CODES (PART 1)
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Monday, January 13 CEC 220 Digital Circuit Design Slide 1 of 14.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Fri, Aug 28 CEC 220 Digital Circuit Design Slide 1 of 14.
2's Complement Arithmetic
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
1 COMS 161 Introduction to Computing Title: Computing Basics Date: September 8, 2004 Lecture Number: 7.
Introduction to Digital Electronics Lecture 2: Number Systems.
ECE DIGITAL LOGIC LECTURE 3: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/19/2016.
In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative The same is true for binary numbers a computer.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
1 CS 151 : Digital Design Chapter 4: Arithmetic Functions and Circuits 4-3 : Binary Subtraction.
ECE 3110: Introduction to Digital Systems Number Systems: signed numbers.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Computer Organization 1 Data Representation Negative Integers.
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
CSE370, Lecture 2 Lecture 2: Number Systems  Logistics Webpage is up! HW1 is posted on the web in the calender --- due.
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.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Lecture 4: Digital Systems & Binary Numbers (4)
2's Complement Arithmetic
Logistics Always read the Calendar at
2’s Complement Arithmetic
CPS120: Introduction to Computer Science
Number Systems Rayat Shikshan Sanstha’s
Number Systems Rayat Shikshan Sanstha’s
ECE 331 – Digital System Design
Lecture 2: Number Systems
Two’s Complement & Binary Arithmetic
Presentation transcript:

Computer Engineering (Logic Circuits) Dr. Tamer Samy Gaafar Lec. # 2 Dept. of Computer & Systems Engineering Faculty of Engineering Zagazig University

Course Web Page http://www.tsgaafar.faculty.zu.edu.eg Email: tsgaafar@yahoo.com

Announcements Sections will start this week (today) A quiz will be held on the next week lecture (23/2/2015) at the 1st 20 mins. The quiz will be on ch.1 as a whole. No cheating is allowed (zero for both cheaters).

Lecture 2 Number Systems (cont.)

Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2N-1. 4 bits = 0 to 15 8 bits = 0 to 255 16 bits = 0 to 65535 Besides simply representation, we would like to also do arithmetic operations on numbers in binary form. Principal operations are addition and subtraction.

Binary Arithmetic, Subtraction The rules for binary arithmetic are: The rules for binary subtraction are: 0 + 0 = 0, carry = 0 0 - 0 = 0, borrow = 0 1 + 0 = 1, carry = 0 1 - 0 = 1, borrow = 0 0 + 1 = 1, carry = 0 0 - 1 = 1, borrow = 1 1 + 1 = 0, carry = 1 1 - 1 = 0, borrow = 0 Borrows, Carries from/to digits to left of current of digit. Binary subtraction, addition works just the same as decimal addition, subtraction.

Binary, Decimal addition 101011 + 000001 --------------- 101100 From LSB to MSB: 1+1 = 0, carry of 1 1 (carry)+1+0 = 0, carry of 1 1 (carry)+0 + 0 = 1, no carry 1 +0 = 1 0 + 0 = 0 1 + 0 = 1 answer = 101100 34 + 17 ------ 51 from LSD to MSD: 7+4 = 1; with carry out of 1 to next column 1 (carry) + 3 + 1 = 5. answer = 51.

Subtraction Decimal Binary 900 100 - 001 ------- 899 0-1 = 9; with borrow of 1 from next column 0 -1 (borrow) - 0 = 9, with borrow of 1 9 - 1 (borrow) - 0 = 8. Answer = 899. 100 - 001 ------- 011 0-1 = 1; with borrow of 1 from next column 0 -1 (borrow) - 0 = 1, with borrow of 1 1 - 1 (borrow) - 0 = 0. Answer = 011.

Signed Numbers Number systems Sign and magnitude Ones-complement ( 9’s Complement ) Twos-complement (10’s Complement )

Arithmetic 6912 10101 Decimal Binary 11 1234 5274 + 5678 – 1638 3636 1011 + 1010 10101 1011 – 0110 0101

Negative numbers Sign and magnitude Ones-complement Twos-complement How do we write negative binary numbers? Prefix numbers with minus symbol? 3 approaches: Sign and magnitude Ones-complement Twos-complement All 3 approaches represent positive numbers in the same way

Sign and magnitude Most significant bit (MSB) is the sign bit 0 ≡ positive 1 ≡ negative Remaining bits are the number's magnitude 0000 0001 0011 1111 1110 1100 1011 1010 1000 0111 0110 0100 0010 0101 1001 1101 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 – 0 – 1 – 2 – 3 – 4 – 5 – 6 – 7

Sign and magnitude Problem 1: Two representations of for zero +0 = 0000 and also –0 = 1000 Problem 2: Arithmetic is cumbersome 4 – 3 != 4 + (-3)

Ones(1’s)-complement Negative number: Bitwise complement of positive number 0111 ≡ 710 1000 ≡ –710 0000 0001 0011 1111 1110 1100 1011 1010 1000 0111 0110 0100 0010 0101 1001 1101 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 – 7 – 6 – 5 – 4 – 3 – 2 – 1 – 0

1’s complement Solves the arithmetic problem end-around carry

Why 1’s complement works The ones-complement of an 4-bit positive number y is 11112 – y 0111 ≡ 710 11112 – 01112 = 10002 ≡ –710 What is 11112? 1 less than 100002 = 24 – 1 –y is represented by (24 – 1) – y

So what's wrong? Still have two representations for zero! +0 = 0000 and also –0 = 1111

Twos (2’s)-complement Negative number: Bitwise complement plus one 0111 ≡ 710 1001 ≡ –710 Benefits: Simplifies arithmetic Only one zero! 0000 0001 0011 1111 1110 1100 1011 1010 1000 0111 0110 0100 0010 0101 1001 1101 + 1 + 2 + 3 + 4 + 5 + 6 + 7 – 8 – 7 – 6 – 5 – 4 – 3 – 2 – 1

2’s complement

Obtaining 2’s complement Recall: The ones-complement of a b-bit positive number y is (2b – 1) – y Twos-complement adds one to the bitwise complement, thus, –y is 2b – y Or Leaving all zeros and the first one from the right as it is then, complement each 0 and 1 after the first 1 from the right

Why 2’s complement works Adding representations of x and –y where x, y are positive numbers, we get x + (2b – y) = 2b + (x – y) If there is a carry, that means that x  y and dropping the carry yields x – y If there is no carry, then x < y, then we can think of it as 2b – (y – x), which is the twos-complement representation of the negative number resulting from x – y.

Miscellaneous Sign-extension Write +6 and –6 as twos-complement 0110 and 1010 Sign-extend to 8-bit bytes 00000110 and 11111010 Can't infer a representation from a number 11001 is 25 (unsigned) 11001 is -9 (sign and magnitude) 11001 is -6 (ones complement) 11001 is -7 (twos complement)

2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics 2's Complement Arithmetic 10’s Complement Process The 10’s Complement process uses base-10 (decimal) numbers. Later, when we’re working with base-2 (binary) numbers, you will see that the 2’s Complement process works in the same way. First, complement all of the digits in a number. A digit’s complement is the number you add to the digit to make it equal to the largest digit in the base (i.e., 9 for decimal). The complement of 0 is 9, 1 is 8, 2 is 7, etc. Second, add 1. Without this step, our number system would have two zeroes (+0 & -0), which no number system has. This slide describes the 10’s complement conversion process. Project Lead The Way, Inc. Copyright 2009

10’s Complement Examples 2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics 10’s Complement Examples Example #1 -003 Complement Digits  996 Add 1 +1 997 Example #2 Examples of the 10’s Complement Process. -214 Complement Digits  785 Add 1 +1 24 786 Project Lead The Way, Inc. Copyright 2009 24

8-Bit Binary Number System Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics 2's Complement Arithmetic 8-Bit Binary Number System Apply what you have learned to the binary number systems. How do you represent negative numbers in this 8-bit binary system? Cut the number system in half. Use 00000001 – 01111111 to indicate positive numbers. Use 10000000 – 11111111 to indicate negative numbers. Notice that 00000000 is not positive or negative. +127 01111111 01111110 01111101 00000001 00000000 11111111 11111110 10000001 10000000 pos(+) +126 +125 +1 -1 Introduction to the 8-Bit Binary Number system and how negative numbers are represented. -2 -127 neg(-) -128 Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics 2's Complement Arithmetic Sign Bit What did do you notice about the most significant bit of the binary numbers? The MSB is (0) for all positive numbers. The MSB is (1) for all negative numbers. The MSB is called the sign bit. In a signed number system, this allows you to instantly determine whether a number is positive or negative. +127 01111111 01111110 01111101 00000001 00000000 11111111 11111110 10000001 10000000 pos(+) +126 +125 +1 -1 Explanation of the sign bit. -2 -127 neg(-) -128 Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics 2's Complement Arithmetic 2’S Complement Process The steps in the 2’s Complement process are similar to the 10’s Complement process. However, you will now use the base two. First, complement all of the digits in a number. A digit’s complement is the number you add to the digit to make it equal to the largest digit in the base (i.e., 1 for binary). In binary language, the complement of 0 is 1, and the complement of 1 is 0. Second, add 1. Without this step, our number system would have two zeroes (+0 & -0), which no number system has. This slide describes the 2’s complement conversion process. Project Lead The Way, Inc. Copyright 2009

2’s Complement Examples Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics 2's Complement Arithmetic 2’s Complement Examples Example #1 5 = 00000101 Complement Digits  11111010 Add 1 +1 -5 = 11111011 Example #2 Examples of the 2’s Complement Process. -13 = 11110011 Complement Digits  00001100 Add 1 +1 13 = 00001101 Project Lead The Way, Inc. Copyright 2009

Using The 2’s Complement Process Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics 2's Complement Arithmetic Using The 2’s Complement Process Use the 2’s complement process to add together the following numbers. POS + POS  9 + 5 14 NEG + POS  (-9) + 5 - 4 This slide show that there are only four possible combinations for adding together two signed numbers. The next four slides demonstrate each of these examples. POS + NEG  9 + (-5) 4 NEG + NEG  (-9) + (-5) - 14 Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics 2's Complement Arithmetic POS + POS → POS Answer If no 2’s complement is needed, use regular binary addition. 9 + 5 14  00001001 + 00000101   00001110 Addition of two Positive numbers. Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics 2's Complement Arithmetic POS + NEG → POS Answer Take the 2’s complement of the negative number and use regular binary addition. 9 + (-5) 4  00001001 + 11111011  1]00000100 8th Bit = 0: Answer is Positive Disregard 9th Bit This example shows the addition of one positive and one negative numbers. Note that this is done in the same way as subtracting a positive number from a positive number. In this case, the answer is positive. 00000101  11111010 +1 11111011 2’s Complement Process Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics 2's Complement Arithmetic POS + NEG → NEG Answer Take the 2’s complement of the negative number and use regular binary addition. (-9) + 5 -4 11110111  + 00000101  11111100 8th Bit = 1: Answer is Negative This slide demonstrates the addition of one positive and one negative number. Again, this is is the same a subtracting a positive number from a positive number. In this case the answer happens to be negative. 11111100  00000011 +1 00000100 To Check: Perform 2’s Complement On Answer 00001001  11110110 +1 11110111 2’s Complement Process Project Lead The Way, Inc. Copyright 2009

2's Complement Arithmetic Digital Electronics  Lesson 2.4 – Specific Comb Circuit & Misc Topics 2's Complement Arithmetic NEG + NEG → NEG Answer Take the 2’s complement of both negative numbers and use regular binary addition. (-9) + (-5) -14  11110111 2’s Complement Numbers, See Conversion Process In Previous Slides 11111011  +  1]11110010 8th Bit = 1: Answer is Negative Disregard 9th Bit This slide demonstrates the addition of two negative numbers. 11110010  00001101 +1 00001110 To Check: Perform 2’s Complement On Answer Project Lead The Way, Inc. Copyright 2009

Overflow Summing two positive numbers can give a negative result Summing two negative numbers can give a positive result 0000 0001 0011 1111 1110 1100 1011 1010 1000 0111 0110 0100 0010 0101 1001 1101 + 1 + 2 + 3 + 4 + 5 + 6 + 7 – 8 – 7 – 6 – 5 – 4 – 3 – 2 – 1 6 + 4 ⇒ –6 –7 – 3 ⇒ +6

Addition Examples (8 bit numbers) Add 7 and 4 (both positive) Add 15 and -6 (positive > negative) Add 16 and -24 (negative > positive) Add -5 and -9 (both negative) 00000111 7 +00000100 +4 00001011 11 00001111 15 +11111010 +(-6) 1 00001001 9 Discard carry 00010000 16 +11101000 +(-24) 11111000 -8 Sign bit is negative so negative number in 2’s complement form 11111011 -5 +11110111 +-9 1 11110010 -14 Discard carry

Subtraction Examples Find 8 minus 3. Find 12 minus -9. 00001000 8 +11111101 -3 1 00000101 5 Discard carry Minuend Subtrahend Difference 00001100 12 +00001001 - -9 00010101 21 11100111 -25 +11101101 - 19 1 11010100 -44 Discard carry 10001000 -120 +00011110 - -30 10100110 -90

BCD Addition

BCD Addition Rules Result must be corrected if 1. Result > 9 (further during all the addition steps) 2. A carry occurs in the first addition step only from one digit ( 4bit binary ) to another.

BCD example 0101 0010 0100 0110 1001 1000 nc Example #1 52 + 46 ----- ---------------- 98 No correction is needed 0101 0010 0100 0110 1001 1000 nc

BCD example Example #2 17 0 0001 0111 + 56 0 0101 0110 ----- --------------------- 73 0 nc 0110 nc 1101 Correction 0 0000 0110 -------------------- 0 0111 0011

BCD example Example #3 39 0 0011 1001 + 28 0 0010 1000 ----- --------------------- 67 0 nc 0110 c 0001 Correction 0 0000 0110 -------------------- 0 0110 0111 Copyright 2009 - Joanne DeGroat, ECE, OSU 9/15/09 - L2

BCD example Example #4 71 0 0111 0001 + 65 0 0110 0101 ----- --------------------- 136 0 nc 1101 nc 0110 Correction 0 0110 0000 -------------------- 0 0001 0011 0110

BCD example Example #5 87 0 1000 0111 + 15 0 0001 0101 ----- --------------------- 102 0 nc 1001 nc 1100 Correction 0 0000 0110 -------------------- 0 1010 0010 0 0110 0000 ------------------------- 0 0001 0000 0010