Lecture 4: Digital Systems & Binary Numbers (4)

Slides:



Advertisements
Similar presentations
Addition and Subtraction. Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement.
Advertisements

Computer Engineering (Logic Circuits) Dr. Tamer Samy Gaafar Lec. # 2
ECE 331 – Digital System Design
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Complements: different approaches for representing negative numbers
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 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.
Data Representation – Chapter 3 Sections 3-2, 3-3, 3-4.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
1.6 Signed Binary Numbers.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Lecture 5.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Number Systems Binary to Decimal Octal to Decimal Hexadecimal to Decimal Binary to Octal Binary to Hexadecimal Two’s Complement.
ECE 331 – Digital System Design Representation and Binary Arithmetic of Negative Numbers and Binary Codes (Lecture #10) The slides included herein were.
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.
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
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.
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.
CEC 220 Digital Circuit Design Binary Codes Mon, Aug 31 CEC 220 Digital Circuit Design Slide 1 of 14.
ECE DIGITAL LOGIC LECTURE 3: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/19/2016.
1 CS 151 : Digital Design Chapter 4: Arithmetic Functions and Circuits 4-3 : Binary Subtraction.
Computer Organization 1 Data Representation Negative Integers.
11001 / 101, / ) Perform subtraction on the given unsigned binary numbers using the 2's complement of the subtrahend. Where the result.
Unit I From Fundamentals of Logic Design by Roth and Kinney.
Representing Positive and Negative Numbers
Negative Number Sign-Magnitude: left-most bit as the sign bit –16 bits –Example: 4-bit numbers is given by is given by ’s complement:
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Computer Representation of Information
Cosc 2150: Computer Organization
David Kauchak CS 52 – Spring 2017
Computer Architecture & Operations I
Number Systems and Codes (parte 1)
Negative Numbers and Subtraction
CHAPTER 9 COMPUTER ARITHMETIC - ALU
Integers’ Representation. Binary Addition. Two's Complement.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
11001 / 101 , / ) Perform subtraction on the given unsigned binary numbers using the 2's complement of the subtrahend. Where the.
Binary Arithmetic Binary arithmetic is essential in all digital computers and in many other types of digital systems. Addition, Subtraction, Multiplication,
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Addition and Substraction
Dr. Clincy Professor of CS
Dr. Clincy Professor of CS
Wakerly Section 2.4 and further
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
EE207: Digital Systems I, Semester I 2003/2004
Data Representation – Chapter 3
Unit 18: Computational Thinking
Digital Systems and Binary Numbers
How are negative and rational numbers represented on the computer?
Dr. Clincy Professor of CS
CPS120: Introduction to Computer Science
Decimal and binary representation systems
Number Systems Rayat Shikshan Sanstha’s
Number Systems Rayat Shikshan Sanstha’s
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
ECE 331 – Digital System Design
Lecture No.5.
COMS 361 Computer Organization
Chapter3 Fixed Point Representation
Chapter 1 (Part c) Digital Systems and Binary Numbers
Two’s Complement & Binary Arithmetic
Presentation transcript:

Lecture 4: Digital Systems & Binary Numbers (4) CPE 201 Digital Design Lecture 4: Digital Systems & Binary Numbers (4)

Lecture Outline Signed numbers Encoding techniques

Signed Binary Numbers Cannot use the “minus” sign we use on paper Signed-magnitude MSB keeps the sign: 0 – positive, 1 – negative Hard to use with arithmetic operations The user determines if the number is signed/not 01001 9 (unsigned binary) or +9 (signed binary) 11001 Other examples: 010101012 = + 8510 110101012 = - 8510 011111112 = + 12710 111111112 = - 12710 000000002 = +0 100000002 = -0 Signed complement used for computer arithmetic Signed 1’s complement and signed 2’s complement 25 (unsigned binary) or -9 (signed binary)

Signed Complement Negative number is indicated by its complement Positive numbers start with 0  complement will always start with 1 (negative number) 2’s complement is most common E.g.: represent -9 on eight bits Represent +9: Signed magnitude: Signed 1’s complement: Signed 2’s complement: 00001001 10001001 11110110 11110111

Signed Binary Numbers Decimal Signed 2’s compl. Signed 1’s compl. Signed mag. +7 +6 +5 +4 +3 +2 +1 +0 -0 -1 -2 -3 -4 -5 -6 -7 -8 0111 0111 0111 0110 0110 0110 0101 0101 0101 0100 0100 0100 0011 0011 0011 0010 0010 0010 0001 0001 0001 0000 0000 0000 - 1111 1000 1111 1110 1001 1110 1101 1010 1101 1100 1011 1100 1011 1100 1011 1010 1101 1010 1001 1110 1001 1000 1111 1000 - -

Addition of Signed Numbers Signed magnitude Just like regular arithmetic Same signs: add magnitudes Different signs: subtract smaller magnitude from larger, keep the sign of the larger magnitude Requires comparison and subtraction Complex circuit design Better to use signed complement representation + 24 + 44 = + 68 + 24 + (-44) = - 20

Addition of Signed Numbers Use 2’s complement: Represent negative numbers in 2’s complement Perform addition as usual MUST USE THE SAME NUMBER OF BITS FOR BOTH NUMBERS AND THE SUM

Addition of Signed Numbers Signed 2’s complement: 3+4, -2+(-6), 6+(-3), 4+(-7) +3 0 0 1 1 + -2 1 1 1 1 1 1 1 0 + + +4 0 1 0 0 + -6 1 1 1 1 1 0 1 0 +7 0 1 1 1 -8 1 1 1 1 1 1 0 0 0 Discard carry +6 0 1 1 0 + +4 0 1 0 0 + + -3 1 1 0 1 + -7 1 0 0 1 +3 1 0 0 1 1 -3 1 1 0 1 Discard carry

Overflow Addition can result in overflow if there isn’t enough space available to represent the result Can occur only if operands have the same sign Overflow occurs when the carry bits into and out of the sign position are different E.g.: 0 1 1 1 + 1 1 1 0 +7 + +7 +14 = -2 !! 1 carry into sign bit carry out of 1 1 0 1 1 0 1 0 + 0 1 1 1 -3 + -6 -9 1 carry into sign bit carry out of = 7 !!

Subtraction with Signed 2’s Complement Take the 2’s complement of the subtrahend (including the sign bit) Add it to the minuend (including the sign bit) Ignore any carry out of the sign-bit Make sure to check for overflow A – (+B) = A + (-B) A – (-B) = A + (+B) Equivalent to taking the 2’s complement

Examples: Subtraction Signed 2’s Complement 4 – 3 = 0100 – 0011 = 0100 + 1101 = 10001 3 – 4 = 0011 – 0100 = 0011 + 1100 = 1111 1111 is equal to -1 in 2’s complement 3 – (-4) = 0011 – (-(0100))in 2’s complement = = 0011 – 1100 = 0011 + 0100 = 0111 = 710 -3 – (-4) = 1101 – 1100 = 1101 + 0100 = 10001 = 110 Discard the carry Instead add 2’s complement Discard the carry

Binary Codes Is binary the only way to encode information? Same information can be coded using a different code The encoding still uses 0’s and 1’s E.g.: represent the decimal values 1-9: Binary: 0001  1001 One out of 9: 000000001, 000000010, 000000100, … 010000000, 100000000 A code is a set of n-bit strings, which assigns a unique string to any symbol

Binary Coded Decimal (BCD) Code In BCD, each decimal digit is represented with its binary encoding Easier for people to understand than binary How many bits do we need to represent numbers 0 through 9 in BCD? 4 bits E.g.: (527)10 = (0101 0010 0111)BCD A number with k digits in decimal requires 4k bits in BCD Do not confuse with binary representation! 5 2 7

Addition using BCD code Similar to adding 4-bit unsigned binary numbers A correction must be made if the result exceeds 1001 (9) Addition result range is 0 to 19 (9+9+1carry) Binary: 0000 to 10011 BCD: 0000 to 11001 The difference in result between the BCD and binary values is 6 (110) If the result is  1010 (10 decimal), adding 6 (110) to the result will correct the problem

BCD Addition Example 5 + 9 , 8 + 8, 9 + 9 Results: 5 + 9 = 0101 + 1001 = 1110 (need correction) add 110: 1110 + 110 = 1 0100 (1410) 8 + 8 = 1000 + 1000 = 10000 (need correction)  add 110: 10000 + 110 = 1 0110 (1610) 9 + 9 = 1001 + 1001 = 10010 (need correction)  add 110: 10010 + 110 = 1 1000 (1810)

Readings Chapter 2 Sections 1.7