Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:

Slides:



Advertisements
Similar presentations
Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
Advertisements

Representing Numbers: Integers
Addition and Subtraction. Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement.
Computer Engineering (Logic Circuits) Dr. Tamer Samy Gaafar Lec. # 2
COE 202: Digital Logic Design Signed Numbers
EMB1006 The Binary System There is no 2 Jonathan-Lee Jones.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Agenda Shortcuts converting among numbering systems –Binary to Hex / Hex to Binary –Binary to Octal / Octal to Binary Signed and unsigned binary numbers.
Assembly Language and Computer Architecture Using C++ and Java
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
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.
Two’s Complement 1.As an action: (Assume the starting value is 1011) 1.Flip the bits from the starting value => Add one to get the answer.
Review Binary Basic Conversion Binary Decimal
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.
Binary Arithmetic Math For Computers.
COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.
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
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Binary Representation and Computer Arithmetic
Computer Systems 1 Fundamentals of Computing Negative Binary.
1 Week 3: Data Representation: Negative Numbers READING: Chapter 3.
Simple Data Type Representation and conversion of numbers
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
CPS120: Introduction to Computer Science Computer Math: Signed Numbers.
Computer Math. The Decimal System How do we represent “One Hundred and Twenty Five”? How do we represent “One Hundred and Twenty Five”? Simple: 125 !!!
Calculating Two’s Complement. The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of.
Chapter 2 Binary Values and Number Systems. 2 2 Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645,
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
Number Representation
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
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.
Two’s Complement. A system used to represent a negative number in binary A system used to represent a negative number in binary Positive numbers start.
Addition and Substraction
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
CPS3340 Computer Architecture Fall Semester, 2013
Outline Binary Addition 2’s complement Binary Subtraction Half Adder
D75P 34R - HNC Computer Architecture Week 4 Signed Integers © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen College unless otherwise.
IT1004: Data Representation and Organization Negative number representation.
EEE342 Digital Electronics Ian McCrumRoom 5B18, Lecture 2: Codes & Arithmetic.
1 COMS 161 Introduction to Computing Title: Computing Basics Date: September 8, 2004 Lecture Number: 7.
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.
Number Systems and Computer Arithmetic Winter 2014 COMP 1380 Discrete Structures I Computing Science Thompson Rivers University.
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.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Computer Organization 1 Data Representation Negative Integers.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Representing Positive and Negative Numbers
Design of Digital Circuits Reading: Binary Numbers
Computer Architecture & Operations I
Negative Binary Numbers
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
CSCI206 - Computer Organization & Programming
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Negative Binary Numbers
Addition and Substraction
TAO1221 COMPUTER ARCHITECTURE AND ORGANIZATION LAB 6
CSCI206 - Computer Organization & Programming
Digital Logic & Design Lecture 02.
Binary to Decimal Conversion
Two’s Complement & Binary Arithmetic
Presentation transcript:

Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying: → → → → 10, which is a binary of the decimal 2 Example:

Exercise Answers:

Representing negative numbers: One way to represent negative numbers would be to make the left most bit a sign bit. if the bit is 1, the number is negative, if the bit is 0 the number is positive! So let's see what 15 and -15 looks like: 15: = Pretty clear distinction right? But here’s the thing. By using that bit for sign, now the maximum positive number we can represent is for 7 bits only: : 127 instead of 255 before. What happens if we make the entire byte all 1’s? : -127

For unsigned numbers, we can represent, where bits = b, 2^b - 1 so for a byte: it's 2 ⁸ - 1 = 255 for 2 bytes or a short: 2¹ ⁶ - 1 = 65,535 for 4 bytes or an int(on 32 bit systems): 2³² - 1 = However for signed numbers: -(2^b-1) to (2^b-1) - 1 byte: -(2 ⁸ -1) to (2 ⁸ ) = - 2 ⁷ to 2 ⁷ - 1 = -128 to 127 short: to and so on.

1's Complement Negative number is stored as bit-wise complement of corresponding positive number. Leftmost bit of positive number is 0. That of negative number is = = Can represent numbers from -32,767 to 32, But, still have two representations for zero: 0 = =

2's Complement Negative number obtained by taking 1's Complement of positive number and adding = 's Comp = 's Comp = Word integer can represent numbers from -32,768 to 32, Byte integer can represent numbers from -128 to One version of zero:

Subtracting binary numbers (Sign Binary Addition) The most common way of subtracting binary numbers is done by first taking the second value (the number to be subtracted) and apply what is known as two's complement, this is done in two steps: 1. complement each digit in turn (change 1 for 0 and 0 for 1). – 1’s complement 2. add 1 (one) to the result. – 2’s complement By applying these steps you are effectively turning the value into a negative number, and as when dealing with decimal numbers, if you add a negative number to a positive number then you are effectively subtracting to the same value. In other words 25 + (-8) = 17, which is the same as writing = 17.

Example: ( ) First we apply two's complement to which gives us Now we need to add , however when you do the addition you always disregard the last carry, so our example would be: which gives us , now we can convert this value into decimal, which gives So the full calculation in decimal is = (correct !!)

Negative numbers The previous example is subtracting a smaller number from a larger number. If you want to subtract a larger number from a smaller number (giving a negative result), then the process is slightly different. Usually, to indicate a negative number, the most significant bit (left hand bit) is set to 1 and the remaining 7 digits are used to express the value. In this format the MSB is referred to as the sign bit.

Example: ( ) 1’s complement and 2’s complement the bigger number which is 120 Then add the result of the 2’s complement to the smaller number (100). 1’s complement and 2’s complement the result of the addition leaving the most significant bit (MSB) which is the sign bit as it is which is 1. Now we can convert this value into a negative decimal, which gives So, the full calculation in decimal is = (correct !!) (120) ’s complement + 1 2’s complement (100) (-20) The sign bit stays the same. It is not 1’s complement and 2’s complement Remember, 1 bit indicates a NEGATIVE sign, whereas 0 bit indicates positive.

Exercise Do subtraction for the following: – – –