Chapter 1 CSCI

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

ENGIN 112 Intro to Electrical and Computer Engineering

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

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

Binary addition example worked out

CHAPTER 2 NUMBER SYSTEMS

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

Hakim Weatherspoon CS 3410 Computer Science Cornell University

COMBINATIONAL LOGIC FUNCTIONS

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

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

Combinational Logic Design Arithmetic Functions and Circuits

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

Systems I: Computer Organization and Architecture

Numbers and Arithmetic

Digital Systems Roberto Muscedere Images 2013 Pearson Education Inc. 1

Lecture 2 Review on Digital Logic (Part 1)

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

Conversions between Decimal and Binary

ECE380 Digital Logic. Positional representation

of Digital Electronics

Digital Systems and Information Part II

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

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

CprE 281: Digital Logic

Logic. Combinational. inputs. outputs. the result. system can

Class Website:

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

FYSE410 DIGITAL ELECTRONICS [1] [2] [3] [4] [5] A number system consists of an ordered set of symbols (digits).

hexadecimal-to-decimal conversion

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

12/31/2010. Digital Operations and Computations Course Notes. 01-Number Systems Text: Unit 1. Overview. What is a Digital System?

Numbers and Arithmetic

Week No. 06: Numbering Systems

Four Important Number Systems

Fundamentals of Digital Design

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

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

Chapter 1. Binary Systems 1-1. Outline. ! Introductions. ! Number Base Conversions. ! Binary Arithmetic. ! Binary Codes. ! Binary Elements 1-2

Unit II Chapter 4:- Digital Logic Contents 4.1 Introduction... 4

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

UNIT II COMBINATIONAL CIRCUITS:

Complement Arithmetic

THE LOGIC OF COMPOUND STATEMENTS

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

CSE 20 DISCRETE MATH. Fall

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

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

Combinational Logic. By : Ali Mustafa

Physics 310 Lecture 10 Microprocessors

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

Modern Algebra Prof. Manindra Agrawal Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

ECE260: Fundamentals of Computer Engineering

ENGIN 112 Intro to Electrical and Computer Engineering

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

B.Sc. PHYSICS III YEAR

Binary addition by hand. Adding two bits

Q 2.0.2: If it s 5:30pm now, what time will it be in 4753 hours? Q 2.0.3: Today is Wednesday. What day of the week will it be in one year from today?

Adders - Subtractors

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

Fundamentals of Mathematics I

CSE 241 Digital Systems Spring 2013

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

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

CHAPTER 7. Exercises 17/ / /2 2 0

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

Combinational Logic. Course Instructor Mohammed Abdul kader

Computer Number Systems

In this unit we will study exponents, mathematical operations on polynomials, and factoring.

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

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.

Number System conversions

CPE100: Digital Logic Design I

1 Computing System 2. 2 Data Representation Number Systems 22

Carry Look Ahead Adders

Counting in Different Number Systems

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

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

Hardware Design I Chap. 4 Representative combinational logic

Math-2A Lesson 2-1. Number Systems

LOGIC GATES. Basic Experiment and Design of Electronics. Ho Kyung Kim, Ph.D.

What s the Deal? MULTIPLICATION. Time to multiply

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

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

Design of Sequential Circuits

ECE 372 Microcontroller Design

NUMBERS AND CODES CHAPTER Numbers

CS1800: Hex & Logic. Professor Kevin Gold

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

Building a Computer Adder

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

Number Representations

CSEN102 Introduction to Computer Science

University of Florida EEL 3701 Fall 2014 Dr. Eric. M. Schwartz Department of Electrical & Computer Engineering Wednesday, 15 October 2014

Ex code

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

Chapter 1 Review of Equations and Inequalities

Sample Marking Scheme

Cs302 Quiz for MID TERM Exam Solved

CHAPTER 1 REAL NUMBERS KEY POINTS

Transcription:

Chapter 1 CSCI-1510-003

What is a Number? An expression of a numerical quantity A mathematical quantity Many types: Natural Numbers Real Numbers Rational Numbers Irrational Numbers Complex Numbers Etc.

Numerical Representation A quantity can be expressed in several ways XIV 1110 2 E 16 14 10 The base 16 8 All of these are symbols used to represent a quantity or value.

What is the Base or Radix? The cardinality of the set of symbols in a number system Cardinality The number of elements in a given set. The value of the highest symbol is always one less than the base. Base 10: S = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Denoted with a subscript 1110 2 E 16 16 8

Examples The base determines the set of symbols Base 10: S = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Base 8: S = {0, 1, 2, 3, 4, 5, 6, 7} Base 5: S = { 0, 1, 2, 3, 4} Base 2: S = {0, 1} Base 16: S =? Borrow the needed digits from the alphabet, so S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}

Why do we care? Without knowing what base you are working in, there is no way to know what quantity is being enumerated. 11 could mean 11 10, 11 2 = 3 10, 11 5 = 6 10 15 could mean 15 10, 15 8 = 13 10, 15 16 = 21 10

Elementary School Flashback

Why is the 1 s column the 1 s column (base 10)? The 10 s the 10 s? Etc Everything to do with the base raised to a power.

Positional Number Representation Base 10 Remember Expanded Notation? a 4 x 10 4 + a 3 x 10 3 + a 2 x 10 2 + a 1 x 10 1 + a 0 x 10 0 Also known as positional notation.

Example 7,392 10 7 x 1000 + 3 x 100 + 9 x 10 + 2 x 1 7 x 10 3 + 3 x 10 2 + 9 x 10 1 + 2 x 10 0

a n r n +a n-1 r n-1 + +a 2 r 2 +a 1 r 1 +a 0 r 0. a -1 r -1 +a -2 r -2 + +a -m r -m Where: r is the radix or base. n is the number of digits to the left of the decimal point m is the number of digits to the right of the decimal point 11

Why do we care? Nice way to convert from any base to decimal. Ex: 1011 2 1 x 2 3 + 0 x 2 2 + 1 x 2 1 + 1 x 2 0 1 x 8 + 0 X 4 + 1 x 2 + 1 x 8 + 2 + 1 11 10 1 12

Using Positional Notation Ex : 75 8 Ex: A2E 16 Ex : 32.14 8 13

Some terminology Bits digits in a binary number Byte 8 bits Base 2 - Binary Base 8 Octal Base 10 - Decimal Base 16 Hexadecimal or Hex Base 32 Duotrigesimal

Base conversion Decimal to any base. Use division Whole numbers Left of the decimal point Use multiplication Fractional part of a number Right of the decimal point 15

Ex: Convert 13 10 to base 2 0 r 1 2 ) 1 r 1 2 ) 3 r 0 2 ) 6 r 1 2 ) 13 How to check your answer 13 10 = 1101 2

Checking your work Scientific notation can be how

Decimal to Binary Conversion Convert 857 10 to base 2. 0 r 1 ) 1 r 1 ) 3 r 0 ) 6 r 1 ) 13 r 0 ) 26 r 1 ) 53 r 1 ) 107 r 0 ) 214 r 0 ) 428 r 1 2 ) 857 10 MSB LSB 1101011001 2 18

Check the result Use Positional Notation 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 512 256 128 64 32 16 8 4 2 1 1 1 0 1 0 1 1 0 0 1 512 + 256 + 64 + 16 + 8 + 1 = 857 10 19

Octal 0 r 1 ) 1 r 5 ) 13 r 3 ) 107 r 1 8 ) 857 857 10 = 1531 8 8 3 8 2 8 1 8 0 512 64 8 1 1 5 3 1 1 x 512 + 5 x 64 + 3 x 8 + 1 x 1 = 857 10 20

Hexadecimal 0 r 3 ) 3 r 5 ) 53 r 9 16 ) 857 857 10 = 359 16 16 2 16 1 16 0 256 16 1 3 5 9 3 x 256 + 5 x 16 + 1 x 9 = 857 10 21

Example 324 10 to base 5 22

Ex 1.4 0.6875 10 to binary.6875 x 2 = 1.3750 = 1 +.3750.3750 x 2 = 0.7500 = 0 +.7500.7500 x 2 = 1.5000 = 1 +.5000.5000 x 2 = 1.0000 = 1 +.0000 0.6875 10 = 0.1011 2 23

Practice 0.513 10 to octal 24

Powers of 2 Conversion between binary, octal, and hexadecimal made easy. Just regroup and convert How to regroup Consider the least number of bits it would take to encode the largest symbol of the new base. 25

Binary-coded Octal 3 bits to encode 7 8 Binary Octal Why? Do the math. 000 0 001 1 010 2 011 3 100 4 101 5 110 6 111 7 26

Binary to Octal 1101 1010 1010 2 110 110 101 010 2 6 6 5 2 Binary Coded Octal 6652 8 To convert from Octal to Binary, do the same thing in reverse 27

Practice Convert 76 10 to binary, then take the result and quickly convert to octal. Now use your octal result and convert back to decimal. You should get the original number. Do the same thing, with 57 10, 438 10 and 311 10

Binary to Hexadecimal How many bits are needed to represent the largest single cypher in hexadecimal? Hint: do the math. 110110101010 2 1101 1010 1010 2 D A A DAA 16 Binary Hexadecimal 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 A 1011 B 1100 C 1101 D 1110 E 1111 F 29

Practice Convert 76 10 to binary, then take the result and quickly convert to hexadecimal. Now use your hexadecimal result and convert back to decimal. You should get the original number. Do the same thing, with 57 10, 438 10 and 311 10

Octal to Hexadecimal and vice versa Almost the same thing. Convert to Binary Then regroup as necessary. Remember you always group from the decimal point to the right or left. 31

Example 237 8 to Hex Convert to binary 2 3 7 010 011 111 2 Regroup 0 1001 1111 2 9 F 16 Does the leading zero mean anything? 32

Why use Hexadecimal and Octal? Convenience Ex. 1011011001010000 2 Better written as: 1011 0110 0101 0000 2 = B65F 16

Unsigned vs Signed Numbers Unsigned All bits are used to show the magnitude of the number. All numbers are considered to be positive Signed Positive and Negative

Signed Numbers There are three basic ways to designate the sign of a number. Sign and magnitude Radix-1 scomplement Radix complement Why using complement? - simplifying the subtraction operation by adding a complement of that number instead of subtraction for that number 15 10 4 10 = 15 10 - (complement of 4 10 ) = 11 10 35

Sign and Magnitude What is taught in school. A value with a sign in front of it How does it work in Binary? Pretty much the same way as Decimal By convention a sign bit is used. 0 positive 1 negative a = 1 111? a = 15 10 (if unsigned) a = -7 (if signed). 36

Complements of Numbers Two basic types Diminished radix complement Defined as: (r n -1) N; given a number N in base r having n digits Radix complement Defined as r n N; given a number N 0 in base r having n digits and 0 if N = 0. In base 10, we have : 9 complement and 10 s complement In base 2, we have : 1 complement and 2 s complement. 37

Diminished Radix Complement AKA R-1 s complement (r n -1) N In base 10: Finding 5 digits the 9 s complement of 1357. We have n = 5; r = 10, N = 1357. Result = (10 5-1) 1357 = 98642 38

Radix Complement Radix complement Defined as r n N; In base 10: Finding 5 digits the 10 s complement of 1357. Result = 10 5 1357 = 98643

Diminished Radix Complement AKA R-1 s complement (r n -1) N In base 2: Finding 8 digits the 1 s complement of 0110 1100. We have n = 8; r = 2, N = 0110 1100 (108 10 ) Result = (2 8-1 ) 108 = 147 10 = 1001 0011. (do directly in base 2): 1111 1111 (8 digits 1) -0110 1100 ------------------ =1001 0011 TRICK by flipping the bits : 0 -> 1 ; 1->0 40

Radix Complement AKA R-1 s complement (r n ) N In base 2: Finding 8 digits the 2 s complement of 0110 1100. We have n = 8; r = 2, N = 0110 1100 (108 10 ) Result = (2 8 ) 108 = 148 10 = 1001 0100. (do directly in base 2): 1 0000 0000 (8 digits 1) -0110 1100 ------------------ = 0 1001 0100 TRICK by flipping the bits : 0 -> 1 ; 1->0. Then Add 1. 41

Practice Finding 8 digits the 1 s complement of 0111 1000. Finding 8 digits the 2 s complement of 0111 1000.

Practice Finding 8 digits the 1 s complement of 0111 1000. Answer: 1000 01111 Finding 8 digits the 2 s complement of 0111 1000. Answer: 1000 1000

(R-1) s complement Octal: 8 s complement and 7 s complement Hexadecimal: 16 s complement and 15 complements. R-1 s complement : (r n -1) N. Radix complement: r n N; 44

Why is this wrong? Find the (R-1) s complement of 56 8 8 2 = 64 64 1 = 63 63 56 = 7 WRONG This is base 10 math not base 8.

The Right Way (8 10 ) 2 = 64 10 = 100 8 100 8 1 8 = 77 8 77 8-56 8 = 21 8 21 8 is the complement of 56 8

The Right Way TRICK: CONVERT TO BINARY. DO TRICK IN BINARY. THEN CONVERT BACK. 21 8 = 010 001 => 101 110 = 56 8

Complements Summary The complement of the complement returns the original number If there is a radix point Calculate the complement as if the radix point was not there. Used in computers to perform subtraction. 48

Complements Summary 1 s complement Is the interim step towards 2 s complement Problem: Two values of 0. + 0: 0000 0000, let s flip all bits - 0: 1111 1111. 2 s complement Most CPU s today use 2 s complement. Only one value 0: 0000 000

Rules of Addition Binary addition 0 2 + 0 2 = 0 2 0 2 + 1 2 = 1 2 + 0 2 = 1 2 1 2 + 1 2 = 10 2 Notice the carry into the next significant bit. 50

Sign and Magnitude Example 0100 1111 2 + 0010 0011 2 Sign bit Carry Result 0 1 0 0 1 1 1 1 0 0 1 0 0 0 1 1 51

Sign and Magnitude Example 0100 1111 2 + 0010 0011 2 79 + 35 Carry 0 0 0 1 1 1 1 0 1 0 0 1 1 1 1 0 0 1 0 0 0 1 1 Result 0 1 1 1 0 0 1 0 = 0111 0010 2 114 52

Sign and Magnitude Another example 1 1111 2 + 1 1011 2 Carry Result 1 1 1 1 1 1 1 0 1 1 =? 53

Sign and Magnitude Another example 1 1111 2 + 1 1011 2-15 + (-11) Carry 1 1 1 1 1 1 1 1 1 1 1 0 1 1 Result 1 1 0 1 0 = 1 1010 2-26 54

Sign and Magnitude And another example. 0100 1111 2 + 0110 0011 2 Carry Result 0 1 0 0 1 1 1 1 0 1 1 0 0 0 1 1 =? 55

Sign and Magnitude Another example. 0100 1111 2 + 0110 0011 2 Carry 1 0 0 1 1 1 1 0 1 0 0 1 1 1 1 0 1 1 0 0 0 1 1 Result 1 0 1 1 0 0 1 0 79 + 99-50 = 1011 0010 2 What Happened??? Should be 178 56

Sign and Magnitude The error is due to overflow Caused by a carry out of the MSB of the number to the sign bit. Signed magnitude works but. Suffers from limitations Adding positive and negative numbers doesn t always work. (overflow) 57

Keep in mind If you add 2 number of the same sign AND the result is a different sign, you have OVERFLOW

Rules of Subraction Use the fact you can add a negative number to get the same result. Ex. 15 10-4 10 = 15 10 + (-4 10 ) = 11 10

Unsigned math Procedure for subtraction of 2 unsigned numbers. Ex: M N = x 1. Add M to the r s complement of N 2. If M N, an end carry is produced which can be discarded. Then x is positive as indicated by the carry-out 3. If M N Then x is negative and in r s complement form 60

Complement Arithmetic What is a complement? Webster s a : something that fills up, completes, or makes perfect. b : the quantity, number, or assortment required to make a thing complete A way to represent negative numbers. Two types R-1 s Complement (diminished radix complement) R s Complement (radix complement) 61

R-1 s Complement A reminder: N = r 1 N N is N in 1 s complement notation where n is the number of bits per word N is a positive integer r is the base 62

R-1 s Complement Word Range: The range of numbers that can be represented in a given number of bits. (r n 1 1) to r n 1 1 Ex: What is the range of signed binary numbers that can be represented in 3 bits? - 3 10 to 3 10

Some Terminology Augend, addend, sum 15 Augend +7 Addend 22 Sum (AKA top number) (AKA bottom number) Minuend, subtrahend, difference 15 Minuend - 7 Subtrahend 8 Difference (AKA top number) (AKA bottom number) 64

1 s Complement (Subtraction) Never complement the top number in a problem. Add the 1 s complement of the bottom number to the top number. This will have the same effect as subtracting the original number. If there is a carry-out, end around carry and add back in. 65

How to Subtract Numbers Step 1: 1 s complement the bottom number. Step 2: Do the math. Step 3: If there is a carry out, end around carry and add it back in. Note: If there is no carry the answer is in 1 s complement form. What does this mean? 66

Examples X = 0111 Y = 0101 X Y Y - X 0111-0101 0111 + 1010 10001 + 1 0010 0101-0111 0101 + 1000 1101 67

Things to notice about 1 s complement Any negative number will have a leading 1. There are 2 representations for 0, 00000 and 11111. Not really a problem, but still have to check for it. There is a solution. 68

R s Complement Word Range A reminder N = r N N is N in 2 s complement notation where n is the number of bits per word N is a positive integer r is the base 69

R s Complement Word Range is: (r n 1 ) to r n 1 1 Ex: What is the range of signed binary numbers that can be represented in 3 bits? (-4 10 to 3 10 ) 70

2 s Complement Subtraction Step 1: 2 s complement the bottom number. Never the top number Step 2: Perform the addition Step 3: if there is a carry out, ignore it. If a number leads with a 1, it is negative and in 2 s complement form. 71

Examples X = 0110 Y = 0101 X Y Y - X 0110-0101 0110 + 1011 10001 0101-0110 0101 + 1010 1111 72

Intro to Binary Logic 73

Overview Two discrete values True or false Yes or no High or low 1 or 0 74

Overview Consists of binary variables and a set of logical operations 3 basic logical operations AND OR NOT Each of which produces a result 75

AND Denoted by a dot ( ) or the absence of a symbol. x y = z = xy Interpreted to mean that z = 1 if and only if (iff) x = 1 and y = 1 otherwise the result is z = 0. 76

AND The results of the operation can be shown by a truth table. Inputs Result x y = 1 if and only if x = 1 and y = 1; otherwise = 0 All inputs must be true for the result to be true. 77

OR Denoted by a plus ( + ) x + y = z Interpreted to mean that z = 1 if x = 1 or y = 1 otherwise the result is z = 0. 78

OR The truth table x + y = 1 if x = 1 or y = 1; otherwise the result is z = 0 At least 1 input must be true for the result to be true. 79

NOT This operation is represented by a prime ( ) x Referred to as the complement operation. 80

Pitfall Binary logic should not be confused with binary arithmetic. + implies OR NOT addition implies AND NOT multiplication Ex: a(b + cd) = a and (b or (c and d)) 81

Another way to describe logic operations

Logic Gates Electronic circuits that operate on one or more input signals to produce an output. 83

Timing Diagram 84

Timing Diagram 85

Timing Diagram 86

Summary Binary logic is comprised of 3 basic operations. AND, NOT, OR Be wary of the pitfall Binary logic is not binary arithmetic Each operation has a matching logic gate 87