Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic



Similar documents
LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

Lecture 2. Binary and Hexadecimal Numbers

Number and codes in digital systems

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

CSI 333 Lecture 1 Number Systems

Computer Science 281 Binary and Hexadecimal Review

Solution for Homework 2

Lecture 8: Binary Multiplication & Division

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

Binary Numbers. Binary Octal Hexadecimal

The string of digits in the binary number system represents the quantity

NUMBER SYSTEMS. 1.1 Introduction

Paramedic Program Pre-Admission Mathematics Test Study Guide

Number Representation

Binary Adders: Half Adders and Full Adders

THE BINARY NUMBER SYSTEM

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Chapter 4 Register Transfer and Microoperations. Section 4.1 Register Transfer Language

Listen and Learn PRESENTED BY MATHEMAGICIAN Mathematics, Grade 7

Subnetting Examples. There are three types of subnetting examples I will show in this document:

Classless Subnetting Explained

Useful Number Systems

Opposites are all around us. If you move forward two spaces in a board game

HOMEWORK # 2 SOLUTIO

2011, The McGraw-Hill Companies, Inc. Chapter 3

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

Z80 Instruction Set. Z80 Assembly Language

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

(Refer Slide Time: 00:01:16 min)

Recall the process used for adding decimal numbers. 1. Place the numbers to be added in vertical format, aligning the decimal points.

MACHINE INSTRUCTIONS AND PROGRAMS

Addition Methods. Methods Jottings Expanded Compact Examples = 15

2.2 Scientific Notation: Writing Large and Small Numbers

Number Systems and Radix Conversion

=

Numbering Systems. InThisAppendix...

Positional Numbering System

2.3 IPv4 Address Subnetting Part 2

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

CS201: Architecture and Assembly Language

Chapter 1: Digital Systems and Binary Numbers

PROBLEMS (Cap. 4 - Istruzioni macchina)

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

Sistemas Digitais I LESI - 2º ano

Binary Numbering Systems

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

TCP/IP Cheat Sheet. A Free Study Guide by Boson Software, LLC

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

DB19. 4-Bit Parallel Adder/ Subtractor. Digital Lab Experiment Board Ver. 1.0

Decimals Adding and Subtracting

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

1 Description of The Simpletron

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

3.1. RATIONAL EXPRESSIONS

Lecture 11: Number Systems

Number of bits needed to address hosts 8

Chapter 2. Binary Values and Number Systems

Objective. Materials. TI-73 Calculator

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

25 Integers: Addition and Subtraction

Grade 6 Math Circles. Binary and Beyond

Adding and Subtracting Positive and Negative Numbers

Chapter 4 -- Decimals

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Two's Complement Adder/Subtractor Lab L03

Session 29 Scientific Notation and Laws of Exponents. If you have ever taken a Chemistry class, you may have encountered the following numbers:

MULTIPLICATION AND DIVISION OF REAL NUMBERS In this section we will complete the study of the four basic operations with real numbers.

Properties of Real Numbers

CS101 Lecture 26: Low Level Programming. John Magee 30 July 2013 Some material copyright Jones and Bartlett. Overview/Questions

BCD (ASCII) Arithmetic. Where and Why is BCD used? Packed BCD, ASCII, Unpacked BCD. BCD Adjustment Instructions AAA. Example

MEP Y9 Practice Book A

Tom wants to find two real numbers, a and b, that have a sum of 10 and have a product of 10. He makes this table.

CPEN Digital Logic Design Binary Systems

Integer Operations. Overview. Grade 7 Mathematics, Quarter 1, Unit 1.1. Number of Instructional Days: 15 (1 day = 45 minutes) Essential Questions

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

Chapter 2: Elements of Java

COMPSCI 210. Binary Fractions. Agenda & Reading

BINARY CODED DECIMAL: B.C.D.

Activity 6.7.4: IPv4 Address Subnetting Part 2

Systems I: Computer Organization and Architecture

(Cat. No L3) Product Data

Decimal Number (base 10) Binary Number (base 2)

Asynchronous counters, except for the first block, work independently from a system clock.

3. Convert a number from one number system to another

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations

Addition and Subtraction of Integers

MANCHESTER COLLEGE Department of Education. Length: 25 minutes Grade Intended: Pre-Algebra (7 th )

Section 1.4 Place Value Systems of Numeration in Other Bases

Binary Representation

An Efficient RNS to Binary Converter Using the Moduli Set {2n + 1, 2n, 2n 1}

Appendix A Installation of Visual C++ and MASM

Data Storage 3.1. Foundations of Computer Science Cengage Learning

3201 Computer Networks 2014/2015 Handout: Subnetting Question

Section IV.1: Recursive Algorithms and Recursion Trees

LESSON 4 Missing Numbers in Multiplication Missing Numbers in Division LESSON 5 Order of Operations, Part 1 LESSON 6 Fractional Parts LESSON 7 Lines,

Transcription:

Today Binary addition Representing negative numbers 2

Binary Addition Consider the following binary numbers: 0 0 1 0 0 1 1 0 0 0 1 0 1 0 1 1 How do we add these numbers? 3

Binary Addition 0 0 1 0 0 1 1 0 0 0 1 0 1 0 1 1 1 4

Binary Addition 0 0 1 0 0 1 1 0 0 0 1 0 1 0 1 1 0 1 And we have a carry now! 5

Binary Addition 0 0 1 0 0 1 1 0 0 0 1 0 1 0 1 1 0 0 1 And we have a carry again! 6

Binary Addition 0 0 1 0 0 1 1 0 0 0 1 0 1 0 1 1 0 0 0 1 and again! 7

Binary Addition 0 0 1 0 0 1 1 0 0 0 1 0 1 0 1 1 1 0 0 0 1 8

Binary Addition 0 0 1 0 0 1 1 0 0 0 1 0 1 0 1 1 0 1 0 0 0 1 One more carry! 9

Binary Addition 0 0 1 0 0 1 1 0 0 0 1 0 1 0 1 1 0 1 0 1 0 0 0 1 10

Binary Addition Behaves just like addition in decimal, but: We carry to the next digit any time the sum of the digits is 2 (decimal) or greater 11

Negative Numbers So far we have only talked about representing non-negative integers What can we add to our binary representation that will allow this? 21

Representing Negative Numbers One possibility: Add an extra bit that indicates the sign of the number We call this the sign-magnitude representation 22

Sign Magnitude Representation +12 0 0 0 0 1 1 0 0 23

Sign Magnitude Representation +12 0 0 0 0 1 1 0 0-12 1 0 0 0 1 1 0 0 24

Sign Magnitude Representation +12 0 0 0 0 1 1 0 0-12 1 0 0 0 1 1 0 0 What is the problem with this approach? 25

Sign Magnitude Representation What is the problem with this approach? Some of the arithmetic operators that we have already developed do not do the right thing 26

Sign Magnitude Representation Operator problems: For example, we have already designed a counter (that implements an increment operation) -12 1 0 0 0 1 1 0 0 27

Sign Magnitude Representation Operator problems: -12 1 0 0 0 1 1 0 0 Increment 28

Sign Magnitude Representation Operator problems: -12 1 0 0 0 1 1 0 0 Increment 1 0 0 0 1 1 0 1 29

Sign Magnitude Representation Operator problems: -12 1 0 0 0 1 1 0 0 Increment -13 1 0 0 0 1 1 0 1!!!! 30

Representing Negative Numbers An alternative: When taking the additive inverse of a number, invert all of the individual bits The leftmost bit still determines the sign of the number 31

One s Complement Representation 12 0 0 0 0 1 1 0 0 Invert -12 1 1 1 1 0 0 1 1 32

One s Complement Representation 12 0 0 0 0 1 1 0 0 Invert -12 1 1 1 1 0 0 1 1 Increment 1 1 1 1 0 1 0 0 33

One s Complement Representation 12 0 0 0 0 1 1 0 0 Invert -12 1 1 1 1 0 0 1 1 Increment -11 1 1 1 1 0 1 0 0 34

One s Complement Representation What problems still exist? 35

One s Complement Representation What problems still exist? We have two distinct representations of zero : 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 36

One s Complement Representation What problems still exist? We can t directly add a positive and a negative number: 12 0 0 0 0 1 1 0 0 + + -5 1 1 1 1 1 0 1 0 37

One s Complement Representation 12 0 0 0 0 1 1 0 0 + + -5 1 1 1 1 1 0 1 0 0 0 0 0 0 1 1 0 38

One s Complement Representation 12 0 0 0 0 1 1 0 0 + + -5 1 1 1 1 1 0 1 0 6 0 0 0 0 0 1 1 0!!!! 39

Representing Negative Numbers An alternative: (a little intuition first) 0 0 0 0 0 0 0 0 0 Decrement 40

Representing Negative Numbers An alternative: (a little intuition first) 0 0 0 0 0 0 0 0 0 Decrement 1 1 1 1 1 1 1 1 41

Representing Negative Numbers An alternative: (a little intuition first) 0 0 0 0 0 0 0 0 0 Define this as Decrement -1 1 1 1 1 1 1 1 1 42

Representing Negative Numbers A few more numbers: 3 0 0 0 0 0 0 1 1 2 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0-1 1 1 1 1 1 1 1 1-2 1 1 1 1 1 1 1 0-3 1 1 1 1 1 1 0 1 46

Two s Complement Representation In general, how do we take the additive inverse of a binary number? 47

Two s Complement Representation In general, how do we take the additive inverse of a binary number? Invert each bit and then add 1 48

Two s Complement Representation Invert each bit and then add 1 5 0 0 0 0 0 1 0 1-5 1 1 1 1 1 0 1 1 Two s complement 49

Two s Complement Representation Now: let s try adding a positive and a negative number: 12 0 0 0 0 1 1 0 0 + + -5 1 1 1 1 1 0 1 1 50

Two s Complement Representation Now: let s try adding a positive and a negative number: 12 0 0 0 0 1 1 0 0 + + -5 1 1 1 1 1 0 1 1 0 0 0 0 0 1 1 1 51

Two s Complement Representation Now: let s try adding a positive and a negative number: 12 0 0 0 0 1 1 0 0 + + -5 1 1 1 1 1 0 1 1 7 0 0 0 0 0 1 1 1 52

Two s Complement Representation Two s complement is used for integer representation in today s processors 53

Two s Complement Representation Two s complement is used for integer representation in today s processors One oddity: we can represent one more negative number than we can positive numbers 54

Implementing Subtraction How do we implement a subtraction operator? (e.g., A B) 55

Implementing Subtraction How do we implement a subtraction operator? (e.g., A B) Take the 2s complement of B Then add this number to A 56