Arithmetic Operations on Binary Numbers

Similar documents
Chapter 1 Review of Number Systems

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

Module 2: Computer Arithmetic

Principles of Computer Architecture. Chapter 3: Arithmetic

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Chapter 10 Binary Arithmetics

CO212 Lecture 10: Arithmetic & Logical Unit

EE 109 Unit 6 Binary Arithmetic

Number System. Introduction. Decimal Numbers

Computer Architecture and Organization

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

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

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

COMPUTER ARITHMETIC (Part 1)

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

Binary Addition & Subtraction. Unsigned and Sign & Magnitude numbers

Number Systems. Both numbers are positive

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

Math in MIPS. Subtracting a binary number from another binary number also bears an uncanny resemblance to the way it s done in decimal.

Chapter 4. Operations on Data

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

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

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

CS 31: Intro to Systems Binary Arithmetic. Kevin Webb Swarthmore College January 26, 2016

carry in carry 1101 carry carry

Number Systems Base r

Signed Binary Numbers

Chapter 1. Digital Systems and Binary Numbers

Chapter 5 : Computer Arithmetic

Chapter 3: part 3 Binary Subtraction

World Inside a Computer is Binary

Chapter 10 - Computer Arithmetic

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29

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

Chapter Two MIPS Arithmetic

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

Chapter 4 Arithmetic

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

Chapter 4 Arithmetic Functions

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

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

Signed umbers. Sign/Magnitude otation

Internal Data Representation

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM

Representation of Non Negative Integers

Chapter 2 Bits, Data Types, and Operations

Chapter 5: Computer Arithmetic. In this chapter you will learn about:

Numbers and Representations


Floating-point representations

Floating-point representations

Learning Objectives. Binary over Decimal. In this chapter you will learn about:

Number Systems CHAPTER Positional Number Systems

CS 64 Week 1 Lecture 1. Kyle Dewey

Computer Organization

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

Bits, Words, and Integers

Chapter 3: Arithmetic for Computers

Chapter 2 Data Representations

Chapter 2 Bits, Data Types, and Operations

2. MACHINE REPRESENTATION OF TYPICAL ARITHMETIC DATA FORMATS (NATURAL AND INTEGER NUMBERS).

Chapter 4 Section 2 Operations on Decimals

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Chapter 2: Number Systems

Data Representation 1

Signed Multiplication Multiply the positives Negate result if signs of operand are different

More about Binary 9/6/2016

Data Representations & Arithmetic Operations

Arithmetic Processing

Digital Fundamentals. Lab 6 2 s Complement / Digital Calculator

Computer Architecture and Organization: L04: Micro-operations

CS & IT Conversions. Magnitude 10,000 1,

DIGITAL ARITHMETIC: OPERATIONS AND CIRCUITS

Chapter 2 Bits, Data Types, and Operations

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

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

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

COMP 122/L Lecture 2. Kyle Dewey

CPS 104 Computer Organization and Programming

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

UNIT-III COMPUTER ARTHIMETIC

Imperial College London Department of Computing

EEM336 Microprocessors I. Arithmetic and Logic Instructions

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

Chapter 5: Computer Arithmetic

UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS

Harry H. Porter, 2006

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

MYcsvtu Notes DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes

Chapter Three. Arithmetic

Sign & Magnitude vs 2 s Complement ( Signed Integer Representa:ons)

D I G I T A L C I R C U I T S E E

Hexadecimal Numbers. Journal: If you were to extend our numbering system to more digits, what digits would you use? Why those?

COMP2611: Computer Organization. Data Representation

Lecture 12 Integers. Computer and Network Security 19th of December Computer Science and Engineering Department

COMP Overview of Tutorial #2

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

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

CO Computer Architecture and Programming Languages CAPL. Lecture 9

Transcription:

Arithmetic Operations on Binary Numbers Because of its widespread use, we will concentrate on addition and subtraction for Two's Complement representation. The nice feature with Two's Complement is that addition and subtraction of Two's complement numbers works without having to separate the sign bits (the sign of the operands and results is effectively built-into the addition/subtraction calculation). Remember: 2 n 1 Two's Complement 2 n 1 1 8 x[4] +7 128 x[8] +127 32768 x[16] +32767 2147483648 x[32] +2147483647 What if the result overflows the representation? If the result of an arithmetic operation is to too large (positive or negative) to fit into the resultant bit-group, then arithmetic overflow occurs. It is normally left to the programmer to decide how to deal with this situation. Add the values and discard any carry-out bit. Two's Complement Addition Examples: using 8-bit two s complement numbers. 1. Add 8 to +3 2. (+3) 0000 0011 3. +( 8) 1111 1000 4. ----------------- 5. ( 5) 1111 1011 6. Add 5 to 2 7. ( 2) 1111 1110 8. +( 5) 1111 1011 9. ----------------- 10. ( 7) 1 1111 1001 : discard carry-out Overflow Rule for addition

If 2 Two's Complement numbers are added, and they both have the same sign (both positive or both negative), then overflow occurs if and only if the result has the opposite sign. Overflow never occurs when adding operands with different signs. i.e. Adding two positive numbers must give a positive result Adding two negative numbers must give a negative result Overflow occurs if (+A) + (+B) = C ( A) + ( B) = +C Example: Using 4-bit Two's Complement numbers ( 8 x +7) ( 7) 1001 +( 6) 1010 ------------ ( 13) 1 0011 = 3 : Overflow (largest ve number is 8) A couple of definitions: Subtrahend: what is being subtracted Minuhend: what it is being subtracted from Example: 612-485 = 127 485 is the subtrahend, 612 is the minuhend, 127 is the result Two's Complement Subtraction Normally accomplished by negating the subtrahend and adding it to the minuhend. Any carry-out is discarded. Example: Using 8-bit Two's Complement Numbers ( 128 x +127) (+8) 0000 1000 0000 1000 (+5) 0000 0101 -> Negate -> +1111 1011 ----- ----------- (+3) 1 0000 0011 : discard carry-out Overflow Rule for Subtraction

If 2 Two's Complement numbers are subtracted, and their signs are different, then overflow occurs if and only if the result has the same sign as the subtrahend. Overflow occurs if (+A) ( B) = C ( A) (+B) = +C Example: Using 4-bit Two's Complement numbers ( 8 x +7) Subtract 6 from +7 (+7) 0111 0111 ( 6) 1010 -> Negate -> +0110 ---------- ----- 13 1101 = 8 + 5 = 3 : Overflow Number Circle for 4-bit Two's Complement numbers Numbers can be added or subtracted by moving round the number circle Clockwise for addition Anti-Clockwise for subtraction (addtion of a negative number)

Overflow occurs when a transition is made from +2 n 1 1 to 2 n 1 when adding from 2 n 1 to +2 n 1 1 when subtracting Two's Complement Summary Addition Add the values, discarding any carry-out bit Subtraction Negate the subtrahend and add, discarding any carry-out bit

Overflow Occurs when adding two positive numbers produces a negative result, or when adding two negative numbers produces a positive result. Adding operands of unlike signs never produces an overflow Notice that discarding the carry out of the most significant bit during Two's Complement addition is a normal occurrence, and does not by itself indicate overflow As an example of overflow, consider adding (80 + 80 = 160) 10, which produces a result of 96 10 in 8-bit two's complement: 01010000 = 80 + 01010000 = 80 ----------- 10100000 = 96 (not 160 because the sign bit is 1.) (largest +ve number in 8 bits is 127) Multiplication and Division No problem with unsigned (always positive) numbers, just use the same standard techiques as in base 10 (remembering that x[n] y[n] = z[2n]) Multiplication Example 1100101 2 111101 2 (101 10 61 10 ) 1100101 101 10 111101 61 10 ---- 1100101 ----------????????????? ---------- Easier to use intermediary results: 1100101 101 10 111101 61 10 ------- 1100101 ---------- 111111001 ------------ 10100100001 -------------

101101110001 ------------- 1100000010001 = 4096 10 + 2048 10 + 16 10 + 1 = 6161 10 ------------- Division Example: 100101 2 101 2 (37 10 5 10 ) 111 result = 7 10 ---- 101)100101 101 1000 101 111 101 10 remainder = 2 10 Multiplication in Two's complement cannot be accomplished with the standard technique since, as far as the machine itself is concerned, for Y[n]: Y 0 Y 2 n Y since, when subtracting from zero, need to "borrow" from next column leftwards. Example: 19 10 in 8-bits = (2 8 19) 10 = 256 10 19 10 = 237 10 = 11101101 2 unsigned = 2 7 + 2 6 + 2 5 + 2 3 + 2 2 + 2 0 = 128 + 64 + 32 + 8 + 4 + 1 = 128 + 109 = 19 10 in Two's Complement Consider X ( Y) Internal manipulation of Y is as 2 n Y Therefore X ( Y) = X (2 n Y) = 2 n X X Y

However the expected result should be 2 2n (X Y) since x[n] y[n] = z[2n] Can perform multiplication by converting the Two's Complement numbers to their absolute values and then negating the result if the signs of the operands are different. Similar for Two's Complement division. Can convert the operands to their absolute values, perform the division, and then negating the result if the signs of the operands are different. Most contemporary architectures implement more sophisiticated algorithms for multiplication and division of Two's Complement numbers. Beyond the scope of this course!