Binary Arithmetic Binary arithmetic is essential in all digital computers and in many other types of digital systems. Addition, Subtraction, Multiplication,

Slides:



Advertisements
Similar presentations
ENGIN112 L4: Number Codes and Registers ENGIN 112 Intro to Electrical and Computer Engineering Lecture 4 Number Codes and Registers.
Advertisements

Digital Fundamentals Floyd Chapter 2 Tenth Edition
CS 151 Digital Systems Design Lecture 3 More Number Systems.
CS 151 Digital Systems Design Lecture 4 Number Codes and Registers.
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
Digital Fundamentals Floyd Chapter 2 Tenth Edition
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.
9/15/09 - L15 Decoders, Multiplexers Copyright Joanne DeGroat, ECE, OSU1 Binary additon & subtraction.
1.6 Signed Binary Numbers.
Digital Logic Chapter 2 Number Conversions Digital Systems by Tocci.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
BINARY ARITHMETIC Binary arithmetic is essential in all digital computers and in many other types of digital systems.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
Digital Logic Design Lecture 3 Complements, Number Codes and Registers.
Number systems & Binary codes MODULE 1 Digital Logic Design Ch1-2 Outline of Chapter 1  1.1 Digital Systems  1.2 Binary Numbers  1.3 Number-base Conversions.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
THE BINARY SYSTEM.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
AEEE2031 Data Representation and Numbering Systems.
Number Systems & Operations
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
Chapter 1: Binary Systems
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.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
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:
N 3-1 Data Types  Binary information is stored in memory or processor registers  Registers contain either data or control information l Data are numbers.
Lecture 4: Digital Systems & Binary Numbers (4)
COMPUTER ORGANIZATION 4 TH LECTURE. ASCII Code  ASCII ( American Standard Code for Information Interchange).  Input and output devices that communicate.
Computer Representation of Information
Chapter 1 Digital Systems and Binary Numbers
Cosc 2150: Computer Organization
Number Systems & Binary Arithmetic
NUMBER SYSTEMS.
EI205 Lecture 2 Dianguang Ma Fall, 2008.
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
CHAPTER 1 : INTRODUCTION
Introduction to Chapter 2
Introduction The term digital is derived from the way computers perform operation, by counting digits. Application of digital technology: television, communication.
Number Systems Give qualifications of instructors:
Chapter 3 Data Representation
Digital Systems Section 8 Multiplexers. Digital Systems Section 8 Multiplexers.
Chapter 1 Digital Systems and Binary Numbers
IT 0213: INTRODUCTION TO COMPUTER ARCHITECTURE
University of Gujrat Department of Computer Science
2 Number Systems and Codes Edited by Jerry Bernardini.
Data Structures Mohammed Thajeel To the second year students
BEE1244 Digital System and Electronics BEE1244 Digital System and Electronic Chapter 2 Number Systems.
INTRODUCTION TO LOGIC DESIGN Chapter 1 Digital Systems and Binary Numbers gürtaçyemişçioğlu.
Complement Theory 1’s and, 2’s complement operation
Complement Theory 1’s and, 2’s complement operation
Digital Logic & Design Lecture 02.
Data Representation – Chapter 3
Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1.
Digital Systems Section 12 Binary Adders. Digital Systems Section 12 Binary Adders.
Unit 18: Computational Thinking
C1 Number systems.
CPS120: Introduction to Computer Science
Binary to Decimal Conversion
ECE 331 – Digital System Design
23/04/2019 Data Representation Conversion.
Chapter 1 (Part c) Digital Systems and Binary Numbers
CHAPTER 69 NUMBER SYSTEMS AND CODES
Two’s Complement & Binary Arithmetic
Presentation transcript:

Binary Arithmetic Binary arithmetic is essential in all digital computers and in many other types of digital systems. Addition, Subtraction, Multiplication, and Division www.educlash.com

Binary Addition Example: The four basic rules for adding binary digits (bits) are as follows: 0 + 0 = 0 sum of 0 with a carry of 0 0 + 1 = 1 sum of 1 with a carry 0f 0 1 + 0 = 1 sum of 1 with a carry of 0 1+ 1 = 10 sum of 0 with a carry 0f 1 1 1 0 1 1 + 0 0 1 1 0 0 Carry Example: Try This: 11 + 11 = ?? www.educlash.com

Binary Subtraction Example: The four basic rules for subtracting bits are as follows: 0 – 0 = 0 with borrow 0 1 – 1 = 0 with borrow 0 1 – 0 = 1 with borrow 0 10 – 1 = 1 0 – 1 with a borrow of 1 1 1 – 0 1 = ?? 1 1 0 1 1 0 Example: Try This: 1 0 1 – 0 1 1 = ??? www.educlash.com

Binary Subtraction Have previously looked at the subtraction operation. A quick review. Just like subtraction in any other base Minuend 10110 Subtrahand - 10010 Difference 00100 And when a borrow is needed. Note that the borrow gives us 2 in the current bit position. . www.educlash.com

And a full example And more ripple - www.educlash.com

In General When there is no borrow into the msb position, then the subtrahend in not larger than the minuend and the result is positive and correct. If a borrow into the msb does occur, then the subtrahend is larger than the minuend. www.educlash.com

Consider Now do the operation 4 – 6 Correct difference is -2 or -0010 www.educlash.com

Two’s compliment But how do you represent a minus sign electronically in a computer? How can you represent it such that arithmetic operations are manageable? There are two types of compliments for each number base system. Have the r’s complement Have the (r-1)’s complement For base 2 have 2’s complement and 1’s complement www.educlash.com

1’s Complement 1’s complement of N is defined as (2n -1)-N. If n=4 have (2n -1) being 1 0000 - 1 = 1111 So for n=4 would subtract any 4-bit binary number from 1111. This is just inverting each bit. Example: 1’s compliment of 1011001 is 0100110 www.educlash.com

2’s complement The 2’s complement is defined as 2n-N Can be done by subtraction of N from 2n or adding 1 to the 1’s complement of a number. For 6 = 0110 The 1’s complement is 1001 The 2’s complement is 1010 www.educlash.com

Operation with 2’s complement Add 4 and -6 Will use the 2’s complement of -6 or 1010 4 0100 -6 1010 1110 And taking the 2’s complement of 1110 get 0001 + 1 = 0010 www.educlash.com

Binary Multiplication The four basic rules for multiplying bits are as follows: 0 X 0 = 0 0 X 1 = 0 1 X 0 = 0 1 X 1 = 1 1 1 X 1 1 = ?? 1 1 X 1 1 +1 1 1 0 0 1 Try This: 1 1 1 X 1 0 1 = ?? Example: www.educlash.com

Binary Division Example: Division in binary follows the same procedure as division in decimal. 1 1 0 ÷ 11 = ?? 1 0 11 1 1 0 1 1 0 0 0 Example: Try This: 1 1 0 ÷ 10 = ?? www.educlash.com

Representing Negative Numbers As there is no third symbol available to store a negative symbol explicitly we must use a bit to show if a number is negative or not. We name this bit the ‘Sign Bit’ We use the leftmost bit. If the ‘Sign Bit’ is 1 then the number is negative, if it is 0 then it is positive. www.educlash.com

Representing Negative Numbers - Sign & Magnitude At first glance it may appear to be simple from this point, for example: 3 = 0 0000011 so -3 = 1 0000011 Sign Bits www.educlash.com

Representing Negative Numbers - Sign & Magnitude The problem with this method is that arithmetic is inconvenient: e.g. +3 + -3 = 0 but 0 0000011 +1 0000011 1 0000110 i.e. not 0 www.educlash.com

Two’s Complement This is a better way to represent negative numbers. Imagine a km clock in a car set at 00000000 kilometres. If the car goes forward one km the reading becomes 00000001. If the meter was turned back one km the reading would be 99999999 km. This could be interpreted as ‘-1’ km. www.educlash.com

-5 -5 = 11111011 Work out the binary number as if it were positive. 5 = 0 0000101 From the left, flip all bits up to the last ‘1’, leave this and any other bits after that alone. -5 = 11111011 Don’t flip the last 1. 1 1 1 1 1 1 1 www.educlash.com

1’s and 2’s Complements of Binary Numbers The 1’s and 2’s Complements of Binary Numbers are very important because they permit the representation of negative numbers. The method of 2’s compliment arithmetic is commonly used in computers to handle negative numbers www.educlash.com

Finding the 1’s Complement The 1’s complement of a binary number is found by changing all 1s to 0s and all 0s to 1s. Example: 1 0 1 1 0 0 1 0 (Binary Number) 0 1 0 0 1 1 0 1 (1’s Complement) NOT Gate www.educlash.com

11111011 From the left, flip all bits up to the last ‘1’, leave this and any other bits after that alone. 00000101 Work out the decimal number as if it were positive. 0 0000101 = 5 Add the minus sign. 11111011 = -5 04/07/2018 www.educlash.com

Finding the 2’s Complement The 2’s complement of a binary number is found by adding 1 to the LSB of the 1’s complement 2's Complement = (1's Complement) + 1 Find the 2’s complement of 10110010 10110010 (Binary number) + 01001101 (1’s complement) 1 (Add 1) 01001110 Example: www.educlash.com

Signed Numbers Digital systems, such as the computer, must be able to handle both positive and negative numbers. A signed binary number consists of both sign and magnitude information. The sign indicates whether a number is positive or negative and the magnitude is the value of the number. There three forms in which signed integer (whole) numbers can be represented in binary: Sign-Magnitude 1’s Complement 2’s Complement www.educlash.com

0 = Positive Number and 1 = Negative Number The Sign Bit The left-most bit in a signed binary number is the sign bit, which tells you whether the number is positive or negative. 0 = Positive Number and 1 = Negative Number Sign-Magnitude Form When a signed binary number is represented in sign-magnitude, the left-most bit is the sign bit and the remaining bits are the magnitude bits. The magnitude bits are in true (uncomplemented) binary for both positive and negative numbers. Decimal number, +25 is expressed as an 8-bit signed binary number using sign-magnitude form as: 00011001 Example: Magnitude Bit Sign Bit www.educlash.com

1’s Complement Form Positive numbers in 1’s complement form are represented the same way as the positive sign-magnitude numbers. Negative numbers, however, are the 1’s complements of the corresponding positive numbers. Example: The decimal number -25 is expressed as the 1’s complement of +25 (00011001) as (11100110) 2’s Complement Form In the 2’s complement form, a negative number is the 2’s complement of the corresponding positive number www.educlash.com

Example: Sign-Magnitude: 1's Complement: 2's Complement: 00100111 Express the decimal number -39 in sign-magnitude, 1’s complement and 2’s complement 00100111 Sign-Magnitude: 00100111 >>> 10100111 1's Complement: 00100111 >>> 11011000 2's Complement: 00100111 >>> 11011001 www.educlash.com

Arithmetic Operations with Signed Number 2’s complement arithmetic used in computers and microprocessor-based system . www.educlash.com

1’s Complement Addition Using 1’s complement numbers, adding numbers is easy. For example, suppose we wish to add +(1100)2 and +(0001)2. Let’s compute (12)10 + (1)10. www.educlash.com

1’s Complement Addition (12)10 = +(1100)2 = 011002 (1)10 = +(0001)2 = 000012 0 1 1 0 0 + 0 0 0 0 1 -------------- 0 0 1 1 0 1 0 1 1 0 1 Add carry Final Result Step 1: Add binary numbers Step 2: Add carry to low-order bit www.educlash.com

1’s Complement Subtraction Let’s compute (12)10 - (1)10. (12)10 = +(1100)2 = 011002 (-1)10 = -(0001)2 = 111102 in 1’s comp. www.educlash.com

1’s Complement Subtraction Step 1: Take 1’s complement of 2nd operand Step 2: Add binary numbers Step 3: Add carry to low order bit 0 1 1 0 0 - 0 0 0 0 1 -------------- + 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 www.educlash.com

2’s Complement Addition Using 2’s complement numbers, adding numbers is easy. For example, suppose we wish to add +(1100)2 and +(0001)2. Let’s compute (12)10 + (1)10. 0 1 1 0 0 + 0 0 0 0 1 -------------- 0 0 1 1 0 1 Add Step 1: Add binary numbers Step 2: Ignore carry bit Final Result Ignore www.educlash.com

2’s Complement Subtraction Using 2’s complement numbers, follow steps for subtraction Let’s compute (12)10 - (1)10. (12)10 = +(1100)2 = 011002 (-1)10 = -(0001)2 = 111112 in 2’s comp. www.educlash.com

2’s Complement Subtraction Step 1: Take 2’s complement of 2nd operand Step 2: Add binary numbers Step 3: Ignore carry bit 0 1 1 0 0 - 0 0 0 0 1 -------------- + 1 1 1 1 1 1 0 1 0 1 1 2’s comp Add Final Result Ignore Carry www.educlash.com

2’s Complement Subtraction: Example #2 Let’s compute (13)10 – (5)10. (13)10 = +(1101)2 = (01101)2 (-5)10 = -(0101)2 = (11011)2 Adding these two 5-bit codes… Discarding the carry bit, the sign bit is seen to be zero, indicating a correct result. Indeed, (01000)2 = +(1000)2 = +(8)10. 0 1 1 0 1 + 1 1 0 1 1 -------------- 1 0 1 0 0 0 carry www.educlash.com

2’s Complement Subtraction: Example #3 Let’s compute (5)10 – (12)10. (-12)10 = -(1100)2 = (10100)2 (5)10 = +(0101)2 = (00101)2 Adding these two 5-bit codes… Here, there is no carry bit and the sign bit is 1. This indicates a negative result, which is what we expect. (11001)2 = -(7)10. If final answer is –ve answer will be in two’s complement 0 0 1 0 1 + 1 0 1 0 0 -------------- 1 1 0 0 1 www.educlash.com

BCD Binary Coded Decimal (BCD) is another way to present decimal numbers in binary form. BCD is widely used and combines features of both decimal and binary systems. Each digit is converted to a binary equivalent. www.educlash.com

BCD To convert the number 87410 to BCD: 8 7 4 8 7 4 1000 0111 0100 = 100001110100BCD Each decimal digit is represented using 4 bits. Each 4-bit group can never be greater than 9. Reverse the process to convert BCD to decimal. www.educlash.com

BCD BCD is not a number system. BCD is a decimal number with each digit encoded to its binary equivalent. A BCD number is not the same as a straight binary number. The primary advantage of BCD is the relative ease of converting to and from decimal. www.educlash.com

Alphanumeric Codes Represents characters and functions found on a computer keyboard. ASCII – American Standard Code for Information Interchange. Seven bit code: 27 = 128 possible code groups Examples of use are: to transfer information between computers, between computers and printers, and for internal storage. www.educlash.com

Gray Code Gray code is not a number system. Digit Binary Gray Code 0000 1 0001 2 0010 0011 3 4 0100 0110 5 0101 0111 6 7 8 1000 1100 9 1001 1101 10 1010 1111 11 1011 1110 12 13 14 15 Gray code is not a number system. It is an alternate way to represent four bit data Only one bit changes from one decimal digit to the next Useful for reducing errors in communication. Can be scaled to larger numbers. credential: bring a computer die photo wafer : This can be an hidden slide. I just want to use this to do my own planning. I have rearranged Culler’s lecture slides slightly and add more slides. This covers everything he covers in his first lecture (and more) but may We will save the fun part, “ Levels of Organization,” at the end (so student can stay awake): I will show the internal stricture of the SS10/20. Notes to Patterson: You may want to edit the slides in your section or add extra slides to taylor your needs. www.educlash.com

Parity Codes Parity codes are formed by concatenating a parity bit, P to each code word of C. In an odd-parity code, the parity bit is specified so that the total number of ones is odd. In an even-parity code, the parity bit is specified so that the total number of ones is even. Information Bits P 1 1 0 0 0 0 1 1  Added even parity bit 0 1 0 0 0 0 1 1  Added odd parity bit www.educlash.com