Binary addition example worked out

Similar documents
Functions. Computers take inputs and produce outputs, just like functions in math! Mathematical functions can be expressed in two ways:

EE260: Digital Design, Spring n Digital Computers. n Number Systems. n Representations. n Conversions. n Arithmetic Operations.

14:332:231 DIGITAL LOGIC DESIGN. Why Binary Number System?

Binary addition by hand. Adding two bits

Chapter 1 CSCI

Systems I: Computer Organization and Architecture

Latches. October 13, 2003 Latches 1

Building a Computer Adder

CHAPTER1: Digital Logic Circuits Combination Circuits

Combinational Logic. By : Ali Mustafa

CS1800: Hex & Logic. Professor Kevin Gold

ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN. Week 2 Dr. Srinivas Shakkottai Dept. of Electrical and Computer Engineering

Numbers and Arithmetic

Digital Techniques. Figure 1: Block diagram of digital computer. Processor or Arithmetic logic unit ALU. Control Unit. Storage or memory unit

Hakim Weatherspoon CS 3410 Computer Science Cornell University

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

Review: Additional Boolean operations

THE LOGIC OF COMPOUND STATEMENTS

Numbers and Arithmetic

We say that the base of the decimal number system is ten, represented by the symbol

Contents. Chapter 2 Digital Circuits Page 1 of 30

ECE/CS 250 Computer Architecture

ECE 250 / CPS 250 Computer Architecture. Basics of Logic Design Boolean Algebra, Logic Gates

E40M. Binary Numbers. M. Horowitz, J. Plummer, R. Howe 1

of Digital Electronics

CHAPTER 2 NUMBER SYSTEMS

Computing via boolean logic. COS 116: 3/8/2011 Sanjeev Arora

Boolean Algebra and Digital Logic 2009, University of Colombo School of Computing

Cs302 Quiz for MID TERM Exam Solved

CSE 20 Discrete Math. Algebraic Rules for Propositional Formulas. Summer, July 11 (Day 2) Number Systems/Computer Arithmetic Predicate Logic

Week No. 06: Numbering Systems

Boolean Algebra & Digital Logic

CSC9R6 Computer Design. Practical Digital Logic

Boolean Algebra, Gates and Circuits

Carry Look Ahead Adders

Why digital? Overview. Number Systems. Binary to Decimal conversion

Chapter 3 Ctd: Combinational Functions and Circuits

Hardware Design I Chap. 4 Representative combinational logic

20. Combinational Circuits

Number System conversions

ENG2410 Digital Design Introduction to Digital Systems. Fall 2017 S. Areibi School of Engineering University of Guelph

We are here. Assembly Language. Processors Arithmetic Logic Units. Finite State Machines. Circuits Gates. Transistors

CSE 241 Digital Systems Spring 2013

Numbering Systems. Contents: Binary & Decimal. Converting From: B D, D B. Arithmetic operation on Binary.

Number System. Decimal to binary Binary to Decimal Binary to octal Binary to hexadecimal Hexadecimal to binary Octal to binary

Slide Set 3. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

School of Computer Science and Electrical Engineering 28/05/01. Digital Circuits. Lecture 14. ENG1030 Electrical Physics and Electronics

Review for Test 1 : Ch1 5

Menu. Review of Number Systems EEL3701 EEL3701. Math. Review of number systems >Binary math >Signed number systems

ECE380 Digital Logic. Positional representation

Binary Multipliers. Reading: Study Chapter 3. The key trick of multiplication is memorizing a digit-to-digit table Everything else was just adding

Fundamentals of Digital Design

Midterm Examination # 1 Wednesday, February 25, Duration of examination: 75 minutes

ENGIN 112 Intro to Electrical and Computer Engineering

Conversions between Decimal and Binary

Computer Science. 19. Combinational Circuits. Computer Science COMPUTER SCIENCE. Section 6.1.

Counting in Different Number Systems

CSE 20 DISCRETE MATH. Fall

S C F F F T T F T T S C B F F F F F T F T F F T T T F F T F T T T F T T T

UNSIGNED BINARY NUMBERS DIGITAL ELECTRONICS SYSTEM DESIGN WHAT ABOUT NEGATIVE NUMBERS? BINARY ADDITION 11/9/2018

Digital Logic (2) Boolean Algebra

Math Lecture 18 Notes

Combinational Logic Design Principles

Every time has a value associated with it, not just some times. A variable can take on any value within a range

Applications. Smartphone, tablet, game controller, antilock brakes, microprocessor, Wires

Computer Science. 20. Combinational Circuits. Computer Science COMPUTER SCIENCE. Section

Digital Systems Overview. Unit 1 Numbering Systems. Why Digital Systems? Levels of Design Abstraction. Dissecting Decimal Numbers

COMBINATIONAL LOGIC FUNCTIONS

SAU1A FUNDAMENTALS OF DIGITAL COMPUTERS

The goal differs from prime factorization. Prime factorization would initialize all divisors to be prime numbers instead of integers*

Digital Systems and Information Part II

Student Responsibilities Week 8. Mat Section 3.6 Integers and Algorithms. Algorithm to Find gcd()

DIGITAL CIRCUIT LOGIC BOOLEAN ALGEBRA (CONT.)

14:332:231 DIGITAL LOGIC DESIGN. 2 s-complement Representation

Digital electronics form a class of circuitry where the ability of the electronics to process data is the primary focus.

UNIVERSITI TENAGA NASIONAL. College of Information Technology

Binary addition (1-bit) P Q Y = P + Q Comments Carry = Carry = Carry = Carry = 1 P Q

Four Important Number Systems

XOR - XNOR Gates. The graphic symbol and truth table of XOR gate is shown in the figure.

Intro To Digital Logic

Boolean algebra. Examples of these individual laws of Boolean, rules and theorems for Boolean algebra are given in the following table.

Numbers & Arithmetic. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See: P&H Chapter , 3.2, C.5 C.

CprE 281: Digital Logic

Digital Systems Roberto Muscedere Images 2013 Pearson Education Inc. 1

CISC 1400 Discrete Structures

Mat Week 8. Week 8. gcd() Mat Bases. Integers & Computers. Linear Combos. Week 8. Induction Proofs. Fall 2013

CS61C : Machine Structures

Part 1: Digital Logic and Gates. Analog vs. Digital waveforms. The digital advantage. In real life...

Implementation of Boolean Logic by Digital Circuits

MC9211 Computer Organization

convert a two s complement number back into a recognizable magnitude.

Combinational Logic Design Arithmetic Functions and Circuits

Chapter 4. Combinational: Circuits with logic gates whose outputs depend on the present combination of the inputs. elements. Dr.

Department of Electrical & Electronics EE-333 DIGITAL SYSTEMS

Computer organization

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Digital Logic

Combinational Logic. Lan-Da Van ( 范倫達 ), Ph. D. Department of Computer Science National Chiao Tung University Taiwan, R.O.C.

ECE 545 Digital System Design with VHDL Lecture 1. Digital Logic Refresher Part A Combinational Logic Building Blocks

CS61C : Machine Structures

Logic Theory in Designing of Digital Circuit & Microprocessor

Transcription:

Binary addition example worked out Some terms are given here Exercise: what are these numbers equivalent to in decimal? The initial carry in is implicitly 0 1 1 1 0 (Carries) 1 0 1 1 (Augend) + 1 1 1 0 (Addend) 1 1 0 0 1 (Sum) most significant bit (MSB) least significant bit (LSB) 0

Basic Gates There are three basic kinds of logic gates Operation: AND of two inputs OR of two inputs NOT (complement) on one input Logic gate: Two Questions: How can we implement such switches? What can we build with Gates? And How? 1

Doing addition with gates Lets do simple stuff first: Can we add two numbers each with just 1 bit? Bit: binary digit 0+0 = 0, 0+1 = 1, 1+0 = 1, and 1+1 =??? 2. But 2 is not a symbol. 10 (just as 5 + 5 is 10 in decimal) Result is 0 with 1 carried over to the next bit.. Whats 1 and 0? High and low voltage respectively. Half adder Result Carry 2

Half adder: result Result This circuit is so common, that it has a name an symbol as a gate by itself: Exclusive OR Exclusive OR Output is 1 iff exactly one of the 2 inputs is 1 3

Adding two bits A half adder is used to add two bits. The result consists of two bits: a sum (the right bit) and a carry out (the left bit) Here is the circuit and its block symbol 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 10 4

Adding three bits But what we really need to do is add three bits: the augend and addend, and the carry in from the right. 1 1 1 0 1 0 1 1 + 1 1 1 0 1 1 0 0 1 X Y C in C out S 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 0 + 0 + 0 = 00 0 + 0 + 0 = 01 0 + 1 + 0 = 01 0 + 1 + 1 = 10 1 + 0 + 0 = 01 1 + 0 + 1 = 10 1 + 1 + 0 = 10 1 + 1 + 1 = 11 5

Full adder circuit Why are these things called half adders and full adders? You can build a full adder by putting together two half adders. 6

A 4-bit adder Four full adders together can make a 4-bit adder There are nine total inputs to the 4-bit adder: two 4-bit numbers, A3 A2 A1 A0 and B3 B2 B1 B0 an initial carry in, CI The five outputs are: a 4-bit sum, S3 S2 S1 S0 a carry out, CO 7

An example of 4-bit addition Let s put our initial example into this circuit: A=1011, B=1110 1 1 1 0 1 1 0 1 1 1 0 0 1 1 0 0 1 Step 1: Fill in all the inputs, including CI=0 Step 2: The circuit produces C1 and S0 (1 + 0 + 0 = 01) Step 3: Use C1 to find C2 and S1 (1 + 1 + 0 = 10) Step 4: Use C2 to compute C3 and S2 (0 + 1 + 1 = 10) Step 5: Use C3 to compute CO and S3 (1 + 1 + 1 = 11) The final answer is 11001 8

Now that we can add, how about some memory? We want to save results computed before, and recall them in a later calculation, for example Gates help us build memory How can a circuit remember anything on its own? After all, the values on the wires are always changing, as outputs are generated in response to inputs. The basic idea is feedback: we make a loop in the circuit, so the circuit outputs are inputs as well When S and R are 0, Q is stable : whatever it was, it stays in that state. Ergo : memory. When S is 1 and R is 0, Q becomes 1 Set and Reset inputs When R is 1 and S is 0, Q becomes 0 9

So, we have built a calculator It is not a computer yet We have to type each step into a calculator We d like to program standard steps E.g. Add 57 numbers sitting in memory in specific places Also, support other operations (subtract..) Two new ideas and components are needed for this: Addressable memory Stored Program Addressable memory Memory organized in a bunch of locations, such that contents of specified location can be brought back to the adder when needed. Each memory location has an address (binary, of course) Stored Program: The instructions for which numbers to operate on, what operation to do (add/subtract,..) and where to store the result The instructions themselves can be represented in binary and stored in the memory! The processor must have circuits to decode and interpret these instructions 10

Components of a basic computer Data ALU (Arithmetic/Logic Unit: Basic operations Memory Program Control and Decoding 11

Summary Controllable Switches are easy to make These switches can be used to put together Logic Gates Logic Gates can be put together to make half adder, full adders and multi-bit adders So we can see they can be used for other such circtuits as well Logic Gates can be used to make circtuits that remember or store data A Computer includes, at its heart : An ALU (Arithmetic Logic Unit) Instruction Decoding and associated circuits Memory Stored Program 12

Number systems To get started, we ll discuss one of the fundamental concepts underlying digital computer design: Deep down inside, computers work with just 1s and 0s. Computers use voltages to represent information. In modern CPUs the voltage is usually limited to 1.6-1.8V to minimize power consumption. It s convenient for us to translate these analog voltages into the discrete, or digital, values 1 and 0. But how can two lousy digits be useful for anything? First, we ll see how to represent numbers with just 1s and 0s. Then we ll introduce special operations for computing with 1s and 0s, by treating them as the logical values true and false. 1 0 Volts 1.8 0 13

Rest of Today s lecture Having seen an overview last week, We will now start a more thorough study Number systems Review of binary number representation How to convert between binary and decimal representations Octal and Hex representations Basic boolean operations AND, OR and NOT The idea of Truth Table Boolean functions and expressions Truth table for Boolean expressions 14

Decimal review Numbers consist of a bunch of digits, each with a weight: 1 6 2. 3 7 5 Digits 100 10 1 1/10 1/100 1/1000 Weights The weights are all powers of the base, which is 10. We can rewrite the weights like this: 1 6 2. 3 7 5 Digits 10 2 10 1 10 0 10-1 10-2 10-3 Weights To find the decimal value of a number, multiply each digit by its weight and sum the products. (1 x 10 2 ) + (6 x 10 1 ) + (2 x 10 0 ) + (3 x 10-1 ) + (7 x 10-2 ) + (5 x 10-3 ) = 162.375 15

Converting binary to decimal We can use the same trick to convert binary, or base 2, numbers to decimal. The only difference is that the weights are powers of 2. For example, here is 1101.01 in binary: 1 1 0 1. 0 1 Binary digits, or bits 2 3 2 2 2 1 2 0 2-1 2-2 Weights (in base 10) The decimal value is: (1 x 2 3 ) + (1 x 2 2 ) + (0 x 2 1 ) + (1 x 2 0 ) + (0 x 2-1 ) + (1 x 2-2 ) = 8 + 4 + 0 + 1 + 0 + 0.25 = 13.25 Powers of 2: 2 0 = 1 2 4 = 16 2 8 = 256 2 1 = 2 2 5 = 32 2 9 = 512 2 2 = 4 2 6 = 64 2 10 = 1024 2 3 = 8 2 7 = 128 16

Converting decimal to binary To convert a decimal integer into binary, keep dividing by 2 until the quotient is 0. Collect the remainders in reverse order. To convert a fraction, keep multiplying the fractional part by 2 until it becomes 0. Collect the integer parts in forward order. Example: 162.375: 162 / 2 = 81 rem 0 81 / 2 = 40 rem 1 40 / 2 = 20 rem 0 20 / 2 = 10 rem 0 10 / 2 = 5 rem 0 5 / 2 = 2 rem 1 2 / 2 = 1 rem 0 1 / 2 = 0 rem 1 0.375 x 2 = 0.750 0.750 x 2 = 1.500 0.500 x 2 = 1.000 So, 162.375 10 = 10100010.011 2 17

Why does this work? This works for converting from decimal to any base Why? Think about converting 162.375 from decimal to decimal. 162 / 10 = 16 rem 2 16 / 10 = 1 rem 6 1 / 10 = 0 rem 1 Each division strips off the rightmost digit (the remainder). The quotient represents the remaining digits in the number. Similarly, to convert fractions, each multiplication strips off the leftmost digit (the integer part). The fraction represents the remaining digits. 0.375 x 10 = 3.750 0.750 x 10 = 7.500 0.500 x 10 = 5.000 18

Base 16 is useful too The hexadecimal system uses 16 digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F You can convert between base 10 and base 16 using techniques like the ones we just showed for converting between decimal and binary. For our purposes, base 16 is most useful as a shorthand notation for binary numbers. Since 16 = 2 4, one hexadecimal digit is equivalent to 4 binary digits. It s often easier to work with a number like B4 instead of 10110100. Hex is frequently used to specify things like 32-bit IP addresses and 24-bit colors. Decimal Binary Hex 0 0000 0 1 0001 1 2 0010 2 3 0011 3 4 0100 4 5 0101 5 6 0110 6 7 0111 7 8 1000 8 9 1001 9 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F 19

Binary and hexadecimal conversions Converting from hexadecimal to binary is easy: just replace each hex digit with its equivalent 4-bit binary sequence. 261.35 16 = 2 6 1. 3 5 16 = 0010 0110 0001. 0011 0101 2 To convert from binary to hex, make groups of 4 bits, starting from the binary point. Add 0s to the ends of the number if needed. Then, just convert each bit group to its corresponding hex digit. 10110100.001011 2 = 1011 0100. 0010 1100 2 = B 4. 2 C 16 Hex Binary Hex Binary Hex Binary Hex Binary 0 0000 4 0100 8 1000 C 1100 1 0001 5 0101 9 1001 D 1101 2 0010 6 0110 A 1010 E 1110 3 0011 7 0111 B 1011 F 1111 20

Number Systems Summary Computers are binary devices. We re forced to think in terms of base 2. Today we learned how to convert numbers between binary, decimal and hexadecimal. We ve already seen some of the recurring themes of architecture: We use 0 and 1 as abstractions for analog voltages. We showed how to represent numbers using just these two signals. Next we ll introduce special operations for binary values and show how those correspond to circuits. 21

Boolean Operations So far, we ve talked about how arbitrary numbers can be represented using just the two binary values 1 and 0. Now we ll interpret voltages as the logical values true and false instead. We ll show: How functions can be defined for expressing computations How to build circuits that implement our functions in hardware 22

Boolean values Earlier, we used electrical voltages to represent two discrete values 1 and 0, from which binary numbers can be formed. It s also possible to think of voltages as representing two logical values, true and false. For simplicity, we often still write digits instead: 1 is true 0 is false True False We will use this interpretation along with special operations to design functions and hardware for doing arbitrary computations. Volts 1.8 0 23

Functions Computers take inputs and produce outputs, just like functions in math! Mathematical functions can be expressed in two ways: An expression is finite but not unique f(x,y) = 2x + y = x + x + y = 2(x + y/2) =... A function table is unique but infinite x y f(x,y) 0 0 0 2 2 6 23 41 87 We can represent logical functions in two analogous ways too: A finite, but non-unique Boolean expression. A truth table, which will turn out to be unique and finite. 24

Basic Boolean operations There are three basic operations for logical values. Operation: AND (product) of two inputs OR (sum) of two inputs NOT (complement) on one input Expression: xy, or x y x + y x Truth table: x y xy x y x+y x x 0 0 0 0 0 0 0 1 0 1 0 0 1 1 1 0 1 0 0 1 0 1 1 1 1 1 1 1 25

Boolean expressions We can use these basic operations to form more complex expressions: f(x,y,z) = (x + y )z + x Some terminology and notation: f is the name of the function. (x,y,z) are the input variables, each representing 1 or 0. Listing the inputs is optional, but sometimes helpful. A literal is any occurrence of an input variable or its complement. The function above has four literals: x, y, z, and x. Precedences are important, but not too difficult. NOT has the highest precedence, followed by AND, and then OR. Fully parenthesized, the function above would be kind of messy: f(x,y,z) = (((x +(y ))z) + x ) 26

Truth tables A truth table shows all possible inputs and outputs of a function. Remember that each input variable represents either 1 or 0. Because there are only a finite number of values (1 and 0), truth tables themselves are finite. A function with n variables has 2 n possible combinations of inputs. Inputs are listed in binary order in this example, from 000 to 111. f(x,y,z) = (x + y )z + x f(0,0,0) = (0 + 1)0 + 1 = 1 f(0,0,1) = (0 + 1)1 + 1 = 1 f(0,1,0) = (0 + 0)0 + 1 = 1 f(0,1,1) = (0 + 0)1 + 1 = 1 f(1,0,0) = (1 + 1)0 + 0 = 0 f(1,0,1) = (1 + 1)1 + 0 = 1 f(1,1,0) = (1 + 0)0 + 0 = 0 f(1,1,1) = (1 + 0)1 + 0 = 1 x y z f(x,y,z) 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 1 27

Primitive logic gates Each of our basic operations can be implemented in hardware using a primitive logic gate. Symbols for each of the logic gates are shown below. These gates output the product, sum or complement of their inputs. Operation: AND (product) of two inputs OR (sum) of two inputs NOT (complement) on one input Expression: xy, or x y x + y x Logic gate: 28

Expressions and circuits Any Boolean expression can be converted into a circuit by combining basic gates in a relatively straightforward way. The diagram below shows the inputs and outputs of each gate. The precedences are explicit in a circuit. Clearly, we have to make sure that the hardware does operations in the right order! (x + y )z + x 29

Boolean operations summary We can interpret high or low voltage as representing true or false. A variable whose value can be either 1 or 0 is called a Boolean variable. AND, OR, and NOT are the basic Boolean operations. We can express Boolean functions with either an expression or a truth table. Every Boolean expression can be converted to a circuit. Next time, we ll look at how Boolean algebra can help simplify expressions, which in turn will lead to simpler circuits. 30