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

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

Chapter 10 Binary Arithmetics

Advanced Computer Architecture-CS501

Lecture 6: Signed Numbers & Arithmetic Circuits. BCD (Binary Coded Decimal) Points Addressed in this Lecture

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

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

Number System. Introduction. Decimal Numbers

Chapter 3: part 3 Binary Subtraction

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

EE 109 Unit 6 Binary Arithmetic

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Review. Steps to writing (stateless) circuits: Create a logic function (one per output)

Chapter 3: Arithmetic for Computers

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

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Chapter 4. Operations on Data

Digital Fundamentals. Lab 6 2 s Complement / Digital Calculator

Computer Architecture and Organization

CS 64 Week 1 Lecture 1. Kyle Dewey

T02 Tutorial Slides for Week 2

Signed Binary Numbers

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

Principles of Computer Architecture. Chapter 3: Arithmetic

Basic Arithmetic (adding and subtracting)

Inf2C - Computer Systems Lecture 2 Data Representation

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

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

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

Arithmetic Operations

Chapter 4 Arithmetic Functions

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0

COMP 122/L Lecture 2. Kyle Dewey

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

Chapter 4. Combinational Logic

COMP2611: Computer Organization. Data Representation

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization

COMP Overview of Tutorial #2

Integer Representation

CS 101: Computer Programming and Utilization

Experiment 7 Arithmetic Circuits Design and Implementation

60-265: Winter ANSWERS Exercise 4 Combinational Circuit Design

World Inside a Computer is Binary

Lecture 8: Addition, Multiplication & Division

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

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

CS/COE 0447 Example Problems for Exam 2 Spring 2011

Arithmetic and Logical Operations

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

CS101 Lecture 04: Binary Arithmetic

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

UNIT IV: DATA PATH DESIGN

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

Binary Arithmetic. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T.

Binary Adders. Ripple-Carry Adder

36 Modular Arithmetic

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

VLSI for Multi-Technology Systems (Spring 2003)

ALU Design. 1-bit Full Adder 4-bit Arithmetic circuits. Arithmetic and Logic Unit Flags. Add/Subtract/Increament/Decrement Circuit

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

Binary Adders: Half Adders and Full Adders

Combinational Circuits

CHAPTER 5: Representing Numerical Data

Arithmetic Processing

Arithmetic for Computers

CO212 Lecture 10: Arithmetic & Logical Unit

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

CO Computer Architecture and Programming Languages CAPL. Lecture 9

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

Module 2: Computer Arithmetic

Number Systems. Readings: , Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs

Addition and multiplication

Department of Electrical and Computer Engineering University of Wisconsin - Madison. ECE/CS 352 Digital System Fundamentals.

Number Systems (2.1.1)

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, THE UNIVERSITY OF NEW MEXICO ECE-238L: Computer Logic Design Fall 2013.

Organisasi Sistem Komputer

Binary Values. CSE 410 Lecture 02

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-2700: Digital Logic Design Winter Notes - Unit 4. hundreds.

Numeric Encodings Prof. James L. Frankel Harvard University

Lecture 3: Binary Subtraction, Switching Algebra, Gates, and Algebraic Expressions

Chapter 2: Number Systems

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

COMBINATIONAL LOGIC CIRCUITS

NUMBER OPERATIONS. Mahdi Nazm Bojnordi. CS/ECE 3810: Computer Organization. Assistant Professor School of Computing University of Utah

CHW 261: Logic Design

2. Integers. 9 * celsius / Celsius to Fahrenheit. Precedence. (9 * celsius / 5) + 32

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

2. Integers. 9 * celsius / Celsius to Fahrenheit. Precedence. (9 * celsius / 5) + 32

Number Systems and Computer Arithmetic

EE 109 Unit 19. IEEE 754 Floating Point Representation Floating Point Arithmetic

MIPS Integer ALU Requirements

Lecture 2: Number Systems

2. Integers. 9 * celsius / Celsius to Fahrenheit. Precedence. (9 * celsius / 5) + 32

Digital Logic Design Exercises. Assignment 1

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

But first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15

Computer Organization

COMP 303 Computer Architecture Lecture 6

VTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS Arithmetic (a) The four possible cases Carry (b) Truth table x y

Transcription:

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

content Karnaugh maps revisited Binary Addition Signed Binary Numbers Binary Subtraction Arithmetic Right-Shift and Bit Number Extension Lecture 4: Signed Binaries and Arithmetic 2

content Karnaugh maps revisited Binary Addition Signed Binary Numbers Binary Subtraction Arithmetic Right-Shift and Bit Number Extension Lecture 4: Signed Binaries and Arithmetic 3

Karnaugh maps with 5 or 6 variables With 3 variables along one edge a Karnaugh map needs to be folded into 3-dimensions and one has to look for cubes instead of rectangels. X s can arbitrarily be assigned a 0 or a 1 and can thus be used to extend cubes. h = (c 2 ) ( t 1 c 1 ) ( t 0 t 1 c 0 ) ( t 0 c 0 c 1 ) Lecture 4: Signed Binaries and Arithmetic 4

content Karnaugh maps revisited Binary Addition Signed Binary Numbers Binary Subtraction Arithmetic Right-Shift and Bit Number Extension Lecture 4: Signed Binaries and Arithmetic 5

Half Adder Example: 0001 + 0011 = 0100 Truth table for a 1-bit half adder: a b S C 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1 S is the result and C is the carry bit, i.e. a bit indicating if there is an overflow and an additional bit is necessary to represent the result. Schematics: Lecture 4: Signed Binaries and Arithmetic 6

Full Adder (1/2) A half adder cannot be cascaded to a binary addition of an arbitrary bit-length since there is no carry input. An extension of the circuit is needed. Full Adder truth table: C in a b S C out 0 0 0 0 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1 1 1 1 Lecture 4: Signed Binaries and Arithmetic 7

Full Adder (2/2) Schematics: Lecture 4: Signed Binaries and Arithmetic 8

content Karnaugh maps revisited Binary Addition Signed Binary Numbers Binary Subtraction Arithmetic Right-Shift and Bit Number Extension Lecture 4: Signed Binaries and Arithmetic 9

Sign and Magnitude representation Maybe the most obvious way of representing positive and negative binary numbers is to add a sign-bit. Example for 8 bit numbers (7-bit magnitude and 1 sign-bit, -127 to +127): 87 = 01010111 87 = 11010111 A problem here is that there is also a signed zero, i.e. +0 and -0, which does not really make sense. Lecture 4: Signed Binaries and Arithmetic 10

Two s complement Representation The two s complement (used in most digital circuits today) is a signed binary number representation that does not have this problem and comes with a number of other convenient properties. In 8-bit two s complement the unsigned numbers 0 to 127 represent themselves, whereas the unsigned numbers 128 to 255 represent the numbers -128 to -1 (=the unsigned number -256). Thus, also in this representation all numbers with the first bit equal to 1 are negative numbers. 87 = 01010111-41 = 11010111 (= 215-256) -87 = 10101001 (= 169-256) Lecture 4: Signed Binaries and Arithmetic 11

Inverting in Two s Complement Finding the inverse of a number in two s complement is simple. The same operation is performed for both, positive to negative and negative to positive: 1. invert each bit 2. add 1 Example: 1. 87=01010111 10101000 2. 10101000+1 = 10101001=-87 1. -87=10101001 01010110 2. 01010110+1 = 01010111=87 Lecture 4: Signed Binaries and Arithmetic 12

content Karnaugh maps revisited Binary Addition Signed Binary Numbers Binary Subtraction Arithmetic Right-Shift and Bit Number Extension Lecture 4: Signed Binaries and Arithmetic 13

Binary Subtraction A really cool property of the two s complement representation is that one can simply add two positive or two negative or a negative and a positive number with a full-adder of the same length, ignore an eventual overflowing carry, and the result will be correct (provided the result is not bigger than the positive maximum (e.g. 127 with 8 bit numbers) and no smaller than the negative minimum(e.g. -128 with 8 bit numbers)). Note that ignoring an overflowing carry in effect is a modulo operation of the result. For example adding two unsigned 8 bit numbers and ignoring an eventual overflow carry (which would mean that the unsigned result is bigger than 255) is performing a modulo 256 operation on the result. Lecture 4: Signed Binaries and Arithmetic 14

Two s Complement Addition/Subtraction 8-bit Examples signed op equiv. unsigned op mod 256 signed res -41-87 215+169 = 384 87-41 87+215 = 302 128-128 46 46 Lecture 4: Signed Binaries and Arithmetic 15

Two s Complement Addition/Subtraction 8-bit Graphically Lecture 4: Signed Binaries and Arithmetic 16

Two s Complement Subtraction Thus, if negative and positive numbers can simply be added, a subtraction can be performed by inverting the number that is to be subtracted and adding them. Thus, to compute a-b: 1. invert b by inverting every single bit 2. add the two numbers and set the carry in signal for the adder to 1 (in order to complete the inversion of b) Lecture 4: Signed Binaries and Arithmetic 17

Arithmetic Right-Shift An arithmetic right-shift is a shift operation that performs a division by two correctly in the two s complement representation. Obviously a so called logic shift that shifts in a 0 from the left would turn a negative number into a positive one, which cannot be correct. Instead, the bit that is shifted in from the left needs to be the former most significant bit (MSB). Note that the result is rounded towards and not towards zero. Examples: decimal binary shifted decimal -3 1101 1110-2 -88 10101000 11010100-44 Lecture 4: Signed Binaries and Arithmetic 18

Extending the bit-length in two s complement A last note that will come in handy for the mandatory exercise: To extend the number of bits with which to represent a signed integer, the additional bits on the left need to be filled in with the formar MSB. Examples: decimal 4 bit 8 bit -2 1110 11111110-5 1011 11111011 5 0101 00000101 Lecture 4: Signed Binaries and Arithmetic 19