Design of Digital Circuits Reading: Binary Numbers. Required Reading for Week February 2017 Spring 2017

Similar documents
Chapter 1 :: From Zero to One

CPE100: Digital Logic Design I

ENGIN 112 Intro to Electrical and Computer Engineering

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

ENGIN 112 Intro to Electrical and Computer Engineering

Numbers and Arithmetic

Math 230 Assembly Language Programming (Computer Organization) Numeric Data Lecture 2

CPE100: Digital Logic Design I

Hakim Weatherspoon CS 3410 Computer Science Cornell University

Conversions between Decimal and Binary

Chapter 1 CSCI

Numbers and Arithmetic

Introduction to Digital Logic Missouri S&T University CPE 2210 Number Systems

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

Introduction to Digital Logic Missouri S&T University CPE 2210 Number Systems

CSE 241 Digital Systems Spring 2013

ECE260: Fundamentals of Computer Engineering

CprE 281: Digital Logic

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

Complement Arithmetic

Week No. 06: Numbering Systems

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

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

Number Theory: Representations of Integers

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

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

hexadecimal-to-decimal conversion

Module 2. Basic Digital Building Blocks. Binary Arithmetic & Arithmetic Circuits Comparators, Decoders, Encoders, Multiplexors Flip-Flops

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

ECE380 Digital Logic. Positional representation

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

Four Important Number Systems

Digital Systems Roberto Muscedere Images 2013 Pearson Education Inc. 1

What are binary numbers and why do we use them? BINARY NUMBERS. Converting decimal numbers to binary numbers

E11 Lecture 1: The Big Picture & Digital Systems. Profs. David Money Harris & Sarah Harris Fall 2011

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

Section 4.7 Scientific Notation

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

CHAPTER 7. Exercises 17/ / /2 2 0

What s the Deal? MULTIPLICATION. Time to multiply

Number Representation and Waveform Quantization

CHAPTER 2 NUMBER SYSTEMS

Announcements. CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis. Today. Mathematical induction. Dan Grossman Spring 2010

Multiplication of signed-operands

Representing signed numbers in Two s Complement notation

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

Ex code

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

Lecture 2 Review on Digital Logic (Part 1)

Fundamentals of Digital Design

Introduction to Digital Logic

THE LOGIC OF COMPOUND STATEMENTS

Logic and Computer Design Fundamentals. Chapter 5 Arithmetic Functions and Circuits

The Magic of Negative Numbers in Computers

Binary addition example worked out

ELEN Electronique numérique

Unit 2 Physical Quantities & Measuring Length

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

Lesson 7 Scientific Notation SI Units Unit Conversions

Number Bases. Ioan Despi. University of New England. August 4, 2013

Representing Numbers on the Computer

Logic Simplification. Boolean Simplification Example. Applying Boolean Identities F = A B C + A B C + A BC + ABC. Karnaugh Maps 2/10/2009 COMP370 1

Topic 1: Digital Data

CMP 334: Seventh Class

ECE 372 Microcontroller Design

Total Time = 90 Minutes, Total Marks = 100. Total /10 /25 /20 /10 /15 /20

0,..., r 1 = digits in radix r number system, that is 0 d i r 1 where m i n 1

Carry Look Ahead Adders

CS1800: Hex & Logic. Professor Kevin Gold

NUMBERS AND CODES CHAPTER Numbers

3. Complete the following table of equivalent values. Use binary numbers with a sign bit and 7 bits for the value

Physics 2A Chapter 1 Notes - Units Fall 2017

EE 109 Final Don t Make the Same Mistake

CSCI 255. S i g n e d N u m s / S h i f t i n g / A r i t h m e t i c O p s.

Save from: cs. Logic design 1 st Class أستاذ المادة: د. عماد

Computer Architecture, IFE CS and T&CS, 4 th sem. Representation of Integer Numbers in Computer Systems

Combinational Logic Design Arithmetic Functions and Circuits

Schedule. ECEN 301 Discussion #25 Final Review 1. Date Day Class No. 1 Dec Mon 25 Final Review. Title Chapters HW Due date. Lab Due date.

ENEL Digital Circuit Design. Final Examination

UNIVERSITI TENAGA NASIONAL. College of Information Technology

Number Representations

CSEN102 Introduction to Computer Science

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

Chapter 4 Number Representations

Unit 1. Scientific activity

Binary logic consists of binary variables and logical operations. The variables are

Computer Number Systems

Introduction to Digital Logic Missouri S&T University CPE 2210 Subtractors

What does such a voltage signal look like? Signals are commonly observed and graphed as functions of time:

Unit 3. Digital encoding

Section 001. Read this before starting! You may use one sheet of scrap paper that you will turn in with your test.

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

Lecture 5: Arithmetic

Logic Theory in Designing of Digital Circuit & Microprocessor

Design of Sequential Circuits

10/12/2016. An FSM with No Inputs Moves from State to State. ECE 120: Introduction to Computing. Eventually, the States Form a Loop

CMP 338: Third Class

ECE/CS 250 Computer Architecture

Binary addition by hand. Adding two bits

Transcription:

Design of Digital Circuits Reading: Binary Numbers Required Reading for Week 1 23-24 February 2017 Spring 2017

Binary Numbers Design of Digital Circuits 2016 Srdjan Capkun Frank K. Gürkaynak http://www.syssec.ethz.ch/education/digitaltechnik_16 Adapted from Digital Design and Computer Architecture, David Money Harris & Sarah L. Harris 2007 Elsevier 2

In This Lecture How to express numbers using only 1s and 0s Using hexadecimal numbers to express binary numbers Different systems to express negative numbers Adding and subtracting with binary numbers 3

8's column 1000's column 2's column 4's column 10's column 100's column 1's column 1's column Carnegie Mellon Number Systems Decimal Numbers 5374 10 = Binary Numbers 1101 2 = 4

1000's column 8's column 10's column 100's column 2's column 4's column 1's column 1's column Carnegie Mellon Number Systems Decimal Numbers 5374 10 = 5 10 3 + 3 10 2 + 7 10 1 + 4 10 0 five thousands three hundreds seven tens four ones Binary Numbers 1101 2 = 1 2 3 + 1 2 2 + 0 2 1 + 1 2 0 = 13 10 one eight one four no two one one 5

Powers of two 2 0 = 2 8 = 2 1 = 2 9 = 2 2 = 2 10 = 2 3 = 2 11 = 2 4 = 2 12 = 2 5 = 2 13 = 2 6 = 2 14 = 2 7 = 2 15 = 6

Powers of two 2 0 = 1 2 8 = 256 2 1 = 2 2 9 = 512 2 2 = 4 2 10 = 1024 2 3 = 8 2 11 = 2048 2 4 = 16 2 12 = 4096 2 5 = 32 2 13 = 8192 2 6 = 64 2 14 = 16384 2 7 = 128 2 15 = 32768 Handy to memorize up to 2 15 7

Binary to Decimal Conversion Convert 10011 2 to decimal 8

Binary to Decimal Conversion Convert 10011 2 to decimal 2 4 1 + 2 3 0 + 2 2 0 + 2 1 1 + 2 0 1 = 9

Binary to Decimal Conversion Convert 10011 2 to decimal 2 4 1 + 2 3 0 + 2 2 0 + 2 1 1 + 2 0 1 = 16 1 + 8 0 + 4 0 + 2 1 + 1 1 = 16 + 0 + 0 + 2 + 1 = 19 10 10

Decimal to Binary Conversion Convert 47 10 to binary 11

Decimal to Binary Conversion Convert 47 10 to binary Start with 2 6 = 64 is 64 47? no do nothing Now 2 5 = 32 12

Decimal to Binary Conversion Convert 47 10 to binary Start with 2 6 = 64 is 64 47? no do nothing Now 2 5 = 32 is 32 47? yes subtract 47 32 =15 Now 2 4 = 16 is 16 15? no do nothing Now 2 3 = 8 is 8 15? yes subtract 15 8 = 7 Now 2 2 = 4 is 4 7? yes subtract 7-4 = 3 Now 2 1 = 2 is 2 3? yes subtract 3-2 =1 Now 2 0 = 1 is 1 1? yes we are done 13

Decimal to binary conversion Convert 47 10 to binary Start with 2 6 = 64 is 64 47? no 0 do nothing Now 2 5 = 32 is 32 47? yes 1 subtract 47 32 =15 Now 2 4 = 16 is 16 15? no 0 do nothing Now 2 3 = 8 is 8 15? yes 1 subtract 15 8 = 7 Now 2 2 = 4 is 4 7? yes 1 subtract 7-4 = 3 Now 2 1 = 2 is 2 3? yes 1 subtract 3-2 =1 Now 2 0 = 1 is 1 1? yes 1 we are done Result is 0101111 2 14

Binary Values and Range N-digit decimal number How many values? Range? Example: 3-digit decimal number 10 3 = 1000 possible values Range: [0, 999] N-bit binary number How many values? Range: Example: 3-digit binary number 2 3 = 8 possible values Range: [0, 7] = [000 2 to 111 2 ] 10 N [0, 10 N - 1] 2 N [0, 2 N - 1] 15

Hexadecimal (Base-16) Numbers Decimal Hexadecimal Binary 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Hexadecimal (Base-16) Numbers Decimal Hexadecimal Binary 0 0 0000 1 1 0001 2 2 0010 3 3 0011 4 4 0100 5 5 0101 6 6 0110 7 7 0111 8 8 1000 9 9 1001 10 A 1010 11 B 1011 12 C 1100 13 D 1101 14 E 1110 15 F 1111 17

Hexadecimal Numbers Binary numbers can be pretty long. A neat trick is to use base 16 How many binary digits represent a hexadecimal digit? 4 (since 2 4 = 16) Example 32 bit number: 0101 1101 0111 0001 1001 1111 1010 0110 18

Hexadecimal Numbers Binary numbers can be pretty long. A neat trick is to use base 16 How many binary digits represent a hexadecimal digit? 4 (since 2 4 = 16) Example 32 bit number: 0101 1101 0111 0001 1001 1111 1010 0110 5 D 7 1 9 F A 6 19

Hexadecimal Numbers Binary numbers can be pretty long. A neat trick is to use base 16 How many binary digits represent a hexadecimal digit? 4 (since 2 4 = 16) Example 32 bit number: 0101 1101 0111 0001 1001 1111 1010 0110 5 D 7 1 9 F A 6 The other way is just as simple C E 2 8 3 5 4 B 20

Hexadecimal Numbers Binary numbers can be pretty long. A neat trick is to use base 16 How many binary digits represent a hexadecimal digit? 4 (since 2 4 = 16) Example 32 bit number: 0101 1101 0111 0001 1001 1111 1010 0110 5 D 7 1 9 F A 6 The other way is just as simple C E 2 8 3 5 4 B 1100 1110 0010 1000 0011 0101 0100 1011 21

Hexadecimal to Decimal Conversion Convert 4AF 16 (or 0x4AF) to decimal 22

Hexadecimal to decimal conversion Convert 4AF 16 (or 0x4AF) to decimal 16 2 4 + 16 1 A + 16 0 F = 256 4 + 16 10 + 1 15 = 1024 + 160 + 15 = 1199 10 23

Bits, Bytes, Nibbles 10010110 most significant bit byte 10010110 least significant bit nibble CEBF9AD7 most significant byte least significant byte 24

Powers of Two 2 10 = 1 kilo 1000 (1024) 2 20 = 1 mega 1 million (1,048,576) 2 30 = 1 giga 1 billion (1,073,741,824) 25

Powers of Two (SI Compatible) 2 10 = 1 kibi 1000 (1024) 2 20 = 1 mebi 1 million (1,048,576) 2 30 = 1 gibi 1 billion (1,073,741,824) 26

Estimating Powers of Two What is the value of 2 24? How many values can a 32-bit variable represent? 27

Estimating Powers of Two What is the value of 2 24? 2 4 2 20 16 million How many values can a 32-bit variable represent? 2 2 2 30 4 billion 28

Addition Decimal + 11 3734 5168 8902 carries Binary + 11 carries 1011 0011 1110 29

Add the Following Numbers 1001 1011 + 0101 + 0110 30

Add the Following Numbers + 1 1001 0101 1110 111 1011 + 0110 10001 OVERFLOW! 31

Overflow Digital systems operate on a fixed number of bits Addition overflows when the result is too big to fit in the available number of bits See previous example of 11 + 6 32

Overflow (Is It a Problem?) Possible faults Security issues 33

Binary Values and Range N-digit decimal number How many values? Range? Example: 3-digit decimal number 10 3 = 1000 possible values Range: [0, 999] N-bit binary number How many values? Range: Example: 3-digit binary number 2 3 = 8 possible values Range: [0, 7] = [000 2 to 111 2 ] 10 N [0, 10 N - 1] 2 N [0, 2 N - 1] 34

Signed Binary Numbers Sign/Magnitude Numbers One s Complement Numbers Two s Complement Numbers 35

Sign/Magnitude Numbers 1 sign bit, N-1 magnitude bits Sign bit is the most significant (left-most) bit Positive number: sign bit = 0 Negative number: sign bit = 1 Example, 4-bit sign/mag representations of ± 6: +6 = - 6 = Range of an N-bit sign/magnitude number: A: a, a, a, a, a A N 1 N 2 2 1 0 n 2 an 1 ( 1) a 2 i 0 i i 36

Sign/Magnitude Numbers 1 sign bit, N-1 magnitude bits Sign bit is the most significant (left-most) bit Positive number: sign bit = 0 Negative number: sign bit = 1 Example, 4-bit sign/mag representations of ± 6: +6 = 0110-6 = 1110 A: a, a, a, a, a A N 1 N 2 2 1 0 n 2 an 1 ( 1) a 2 i 0 i i Range of an N-bit sign/magnitude number: [-(2 N-1-1), 2 N-1-1] 37

Problems of Sign/Magnitude Numbers Addition doesn t work, for example -6 + 6: 1110 + 0110 10100 wrong! Two representations of 0 (± 0): 1000 0000 Introduces complexity in the processor design (Was still used by some early IBM computers) 38

One s Complement A negative number is formed by reversing the bits of the positive number (MSB still indicates the sign of the integer): 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 Complement One s Unsigned 0 0 0 0 0 0 0 0 = +0 0 0 0 0 0 0 0 0 1 = 1 1 0 0 0 0 0 0 1 0 = 2 2 0 1 1 1 1 1 1 1 = 127 127 1 0 0 0 0 0 0 0 = -127 128 1 0 0 0 0 0 0 1 = -126 129 1 1 1 1 1 1 0 1 = -2 253 1 1 1 1 1 1 1 0 = -1 254 1 1 1 1 1 1 1 1 = -0 255 39

One s Complement A negative number is formed by reversing the bits of the positive number (MSB still indicates the sign of the integer): 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 Complement One s Unsigned 0 0 0 0 0 0 0 0 = +0 0 0 0 0 0 0 0 0 1 = 1 1 0 0 0 0 0 0 1 0 = 2 2 0 1 1 1 1 1 1 1 = 127 127 1 0 0 0 0 0 0 0 = -127 128 1 0 0 0 0 0 0 1 = -126 129 1 1 1 1 1 1 0 1 = -2 253 1 1 1 1 1 1 1 0 = -1 254 1 1 1 1 1 1 1 1 = -0 255 40

One s Complement The range of n-bit one s complement numbers is: [-2 n-1-1, 2 n-1-1] 8 bits: [-127,127] Addition: Addition of signed numbers in one's complement is performed using binary addition with end-around carry. If there is a carry out of the most significant bit of the sum, this bit must be added to the least significant bit of the sum: Example: 17 + (-8) in 8-bit one s complement 0001 0001 (17) + 1111 0111 (-8) 1 0000 1000 + 1 0000 1001 = (9) 41

Two s Complement Numbers Don t have same problems as sign/magnitude numbers: Addition works Single representation for 0 Has advantages over one s complement: Has a single zero representation Eliminates the end-around carry operation required in one's complement addition 42

Two s Complement Numbers A negative number is formed by reversing the bits of the positive number (MSB still indicates the sign of the integer) and adding 1: 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 Complement Two s Unsigned 0 0 0 0 0 0 0 0 = 0 0 0 0 0 0 0 0 0 1 = 1 1 0 0 0 0 0 0 1 0 = 2 2 0 1 1 1 1 1 1 1 = 127 127 1 0 0 0 0 0 0 0 = -255 128 1 0 0 0 0 0 0 1 = -254 129 1 1 1 1 1 1 0 1 = -3 253 1 1 1 1 1 1 1 0 = -2 254 1 1 1 1 1 1 1 1 = -1 255 43

Two s Complement Numbers A negative number is formed by reversing the bits of the positive number (MSB still indicates the sign of the integer) and adding 1: 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 Complement Two s Unsigned 0 0 0 0 0 0 0 0 = 0 0 0 0 0 0 0 0 0 1 = 1 1 0 0 0 0 0 0 1 0 = 2 2 0 1 1 1 1 1 1 1 = 127 127 1 0 0 0 0 0 0 0 = -128 128 1 0 0 0 0 0 0 1 = -127 129 1 1 1 1 1 1 0 1 = -3 253 1 1 1 1 1 1 1 0 = -2 254 1 1 1 1 1 1 1 1 = -1 255 44

Two s Complement Numbers Same as unsigned binary, but the most significant bit (msb) has value of -2 N-1 i=n-2 I = b i 2 i b n-1 2 n-1 i=0 Most positive 4-bit number: Most negative 4-bit number: The most significant bit still indicates the sign (1 = negative, 0 = positive) Range of an N-bit two s comp number: 45

Two s Complement Numbers Same as unsigned binary, but the most significant bit (msb) has value of -2 N-1 i=n-2 I = b i 2 i b n-1 2 n-1 i=0 Most positive 4-bit number: 0111 Most negative 4-bit number: 1000 The most significant bit still indicates the sign (1 = negative, 0 = positive) Range of an N-bit two s comp number: [-2 N-1, 2 N-1-1] 8 bits: [-128,127] 46

Taking the Two s Complement How to flip the sign of a two s complement number: Invert the bits Add one Example: Flip the sign of 3 10 = 0011 2 47

Taking the Two s Complement How to flip the sign of a two s complement number: Invert the bits Add one Example: Flip the sign of 3 10 = 0011 2 Invert the bits 1100 2 48

Taking the Two s Complement How to flip the sign of a two s complement number: Invert the bits Add one Example: Flip the sign of 3 10 = 0011 2 Invert the bits 1100 2 Add one 1101 2 49

Taking the Two s Complement How to flip the sign of a two s complement number: Invert the bits Add one Example: Flip the sign of 3 10 = 0011 2 Invert the bits 1100 2 Add one 1101 2 Example: Flip the sign of -8 10 = 11000 2 50

Taking the Two s Complement How to flip the sign of a two s complement number: Invert the bits Add one Example: Flip the sign of 3 10 = 0011 2 Invert the bits 1100 2 Add one 1101 2 Example: Flip the sign of -8 10 = 11000 2 Invert the bits 00111 2 Add one 01000 2 51

Two s Complement Addition Add 6 + (-6) using two s complement numbers + 0110 1010 Add -2 + 3 using two s complement numbers + 1110 0011 52

Two s Complement Addition Add 6 + (-6) using two s complement numbers 111 0110 + 1010 10000 Add -2 + 3 using two s complement numbers Correct results if overflow bit is ignored + 111 1110 0011 10001 53

Increasing Bit Width A value can be extended from N bits to M bits (where M > N) by using: Sign-extension Zero-extension 54

Sign-Extension Sign bit is copied into most significant bits Number value remains the same Give correct result for two s complement numbers Example 1: 4-bit representation of 3 = 0011 8-bit sign-extended value: 00000011 Example 2: 4-bit representation of -5 = 1011 8-bit sign-extended value: 11111011 55

Zero-Extension Zeros are copied into most significant bits Value will change for negative numbers Example 1: 4-bit value = 0011 2 = 3 10 8-bit zero-extended value: 00000011 2 = 3 10 Example 2: 4-bit value = 1011 2 = -5 10 8-bit zero-extended value: 00001011 2 = 11 10 56

Number System Comparison Number System Range Unsigned [0, 2 N -1] Sign/Magnitude [-(2 N-1-1), 2 N-1-1] Two s Complement [-2 N-1, 2 N-1-1] For example, 4-bit representation: -8-7 -6-5 -4-3 -2-1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Unsigned 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111 Two's Complement 1111 1110 1101 1100 1011 1010 1001 0000 0001 0010 0011 0100 0101 0110 0111 1000 Sign/Magnitude 57

Lessons Learned How to express decimal numbers using only 1s and 0s How to simplify writing binary numbers in hexadecimal Adding binary numbers Methods to express negative numbers Sign Magnitude One s complement Two s complement (the one commonly used) 58