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.

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

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

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

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

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

Conversions between Decimal and Binary

CprE 281: Digital Logic

ENGIN 112 Intro to Electrical and Computer Engineering

CHAPTER 2 NUMBER SYSTEMS

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

Binary addition example worked out

Chapter 1 CSCI

Four Important Number Systems

ECE380 Digital Logic. Positional representation

EDULABZ INTERNATIONAL NUMBER SYSTEM

Numbers and Arithmetic

Advanced Boolean Logic and Applications to Control Systems

ECE260: Fundamentals of Computer Engineering

3.3 Dividing Polynomials. Copyright Cengage Learning. All rights reserved.

Combinational Logic Design Arithmetic Functions and Circuits

Numbers and Arithmetic

Warm-Up. Simplify the following terms:

Hakim Weatherspoon CS 3410 Computer Science Cornell University

Number Theory: Representations of Integers

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

A group of figures, representing a number, is called a numeral. Numbers are divided into the following types.

L1 2.1 Long Division of Polynomials and The Remainder Theorem Lesson MHF4U Jensen

Multiplication of signed-operands

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

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

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

CprE 281: Digital Logic

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

ALGEBRA 1. Interactive Notebook Chapter 2: Linear Equations

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

CSE 241 Digital Systems Spring 2013

L1 2.1 Long Division of Polynomials and The Remainder Theorem Lesson MHF4U Jensen

A number that can be written as, where p and q are integers and q Number.

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

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

Complement Arithmetic

Section 3-4: Least Common Multiple and Greatest Common Factor

Chapter 5: Exponents and Polynomials

Week No. 06: Numbering Systems

Graduate Institute of Electronics Engineering, NTU Basic Division Scheme

Part I, Number Systems. CS131 Mathematics for Computer Scientists II Note 1 INTEGERS

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

ALU (3) - Division Algorithms

2.5 정수와알고리즘 (Integers and Algorithms)

Combinational Logic. By : Ali Mustafa

Notes on arithmetic. 1. Representation in base B

CSCI 2150 Intro to State Machines

Base-b representations of integers. (b 진법표현 ) Algorithms for computer arithmetic: Euclidean algorithm for finding GCD s.

Measurement and Instrumentation. Sampling, Digital Devices, and Data Acquisition

3 The fundamentals: Algorithms, the integers, and matrices

2 ways to write the same number: 6,500: standard form 6.5 x 10 3 : scientific notation

Multiplying and dividing integers Student Activity Sheet 2; use with Exploring Patterns of multiplying and dividing integers

Counting in Different Number Systems

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

What is Binary? Digital Systems and Information Representation. An Example. Physical Representation. Boolean Algebra

More Polynomial Equations Section 6.4

EECS150 - Digital Design Lecture 24 - Arithmetic Blocks, Part 2 + Shifters

CSCI 220: Computer Architecture-I Instructor: Pranava K. Jha. BCD Codes

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

Hardware Design I Chap. 4 Representative combinational logic

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

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

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

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

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

4 Number Theory and Cryptography

hexadecimal-to-decimal conversion

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

ENGIN 112 Intro to Electrical and Computer Engineering

Chapter 1: Fundamentals of Algebra Lecture notes Math 1010

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

Bell Quiz 2-3. Determine the end behavior of the graph using limit notation. Find a function with the given zeros , 2. 5 pts possible.

1. Introduction to commutative rings and fields

Fundamentals of Mathematics (MATH 1510)

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

Exam for Physics 4051, October 31, 2008

Ch 7 Summary - POLYNOMIAL FUNCTIONS

Computer Architecture 10. Residue Number Systems

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

CMP 334: Seventh Class

Name. Academic Chemistry Measurement and Calculations. Notes. Measurement cincochem.pbworks.com 1

Fundamentals of Digital Design

Answers (1) A) 36 = - - = Now, we can divide the numbers as shown below. For example : 4 = 2, 2 4 = -2, -2-4 = -2, 2-4 = 2.

Lesson/Unit Plan Name: Using Multiple Methods to Perform Operations with Scientific Notation

The Magic of Negative Numbers in Computers

Number Representation and Waveform Quantization

CprE 281: Digital Logic

This Unit: Arithmetic. CIS 371 Computer Organization and Design. Pre-Class Exercise. Readings

Test Bank Questions. (a) Is there an integer n such that n has? (b) Does there exist such that if n is divided by 4 the remainder is 1 and if?

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

Mathematics Pacing. Instruction: 9/7/17 10/31/17 Assessment: 11/1/17 11/8/17. # STUDENT LEARNING OBJECTIVES NJSLS Resources

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

ELEN Electronique numérique

The Euclidean Algorithm and Multiplicative Inverses

not to be republished NCERT REAL NUMBERS CHAPTER 1 (A) Main Concepts and Results

Transcription:

Ying.Yang 1.-1 CSCI 255 http://cs.furman.edu

In mathematics, negative integers exists -> forced to do it binary In a binary string, the MSB is sacrificed as the signed bit 0 => Positive Value 1 => Negative Vale Two different ways were developed: One s complement Two s complement Shifting LEFT/RIGHT Adding/Subtracting Multiplying/Dividing

+ Let s start with stuff that is already known: ADDITION Single bit additions looks like this: 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 These are not OR operations!! We are actually adding. 1 + 1 = 0, carry of 1

+ A quick example of BASE2 Addition: + 1 0 1 1 1 1 10010110 + 10111 1 10010110 + 10111 1 1 10010110 + 10111 1 1 0 1 0 1 1 10010110 + 10111 0 1 1 0 1 1 0 1 + 1 0 1 1 1 1 0 1 1 0 1 + 1 0 1 1 1 + 1 0 1 1 1 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 You can always check the result by converting the two numbers and the result to BASE10

+ Another example of BASE2 Addition: 1 0 1 1 0 0 1 1 0 0 + 1 0 1 1 1 1 1 10110 01100 + 10111 0 1 10 1 0 1 1 0 0 1 1 0 0 + 1 0 1 1 1 0 0 1 1+1+1+1=4; 410=> 1 002 1 10110 01100 + 10111 1 10110 01100 + 10111 1 0 0 1 1 1 0 0 1 1 10110 01100 + 10111 11 1 0 0 1 This is known as the Carry Bit

If we can ADD, then we can SUBTRACT Before we move to that We must learn the ways of the machines It s a simple trick: If you just add the first number by the negative representation of the second number, you end up subtracting This is known as Subtracting by Adding : 9-7 2 9 + -7 2 So, we must learn in how to turn Binary numbers to its negative representation

There are two ways: 1 s Complement 2 s Complement As previously mentioned, the MSB is used as the SIGN BIT: 0 => Positive Value 1 => Negative Vale Ex: 0000 1010 => +value (+10) 1001 0011 => -value (-108)

1 s 1 s complement: First and quick way to represent negation All you do: Complement all the bits Ex: 00000101 => + 5 Applying the NOT operation 1 1 1 1 1 0 1 0 => -5 How to know it is negative 5? MSB/Sign bit is 1 (negative) The zero placements represents the signed value (1+4=5)

1 s The trend/sequence of negative values using 1 s complement is: Negative binary Signed value 11111 0 11110-1 11101-2 11100-3 11011-4 11010-5 11001-6 11000-7 Negative binary Signed value 10111-8 10110-9 10101-10 10100-11 10011-12 10010-13 10001-14 10000-15

2 s 2 s complement: Improvement of 1 s complement What s the improvement? It s a great midterm question. Two ways to perform 2 s complement First way: perform 1 s complement and add 1 0 0 0 0 0 1 0 1 => + 5 Applying 1 s complement 1 1 1 1 1 0 1 0 Add 1 1 1 1 1 1 0 1 0 + 1 1 1 1 1 1 0 1 1-5 in 2 s Complement

2 s 2nd way: From right-to-left, spot the first logical 1 and complement the rest of the bits 1 0 0 0 0 0 1 0 1 => + 5 2 0 0 0 0 0 1 0 1 3 0 0 0 0 0 1 0 1 A 1 spotted, leave it alone, move to the next bit Start complementing from this point 4 1 1 1 1 1 0 1 1 2 s complement representation

2 s The trend/sequence of negative values using 2 s complement is: Negative binary Signed value 11111-1 11110-2 11101-3 11100-4 11011-5 11010-6 11001-7 11000-8 Negative binary Signed value 10111-9 10110-10 10101-11 10100-12 10011-13 10010-14 10001-15 10000-16

- Let s continue with stuff that is already known: SUBTRACTION Single bit subtraction looks like this: 0-0 = 0 0-1 = 1, with borrow 1-0 = 1 These are not1 s or 2 s Complements 1-1 = 0

- A quick example of BASE2 Subtraction: - 1 0 1 1 1 10 10010100-10111 10 10010000-10111 Need to borrow first 10 10000000-10111 1 10 1 1 1 0 0 0 0 0 0 0-1 0 1 1 1 1 1 1 0 0 0 0 0 0 0-1 0 1 1 1 11 10 11 10001000-10111 1 1 1 11 10001000-10111 1 1 1 1 1 1 1 1 1 1 1 1 150-23 127 1 1 1 1

- A quick example of 2 s complement Subtraction: - 1 0 1 1 1 Change 2 nd value to 2 s complement 1 1 1 0 1 0 0 0 + 1 1 1 1 1 1 1 0 1 0 0 0 + 1 10 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 + 1 1 1 1 1 0 1 0 0 0 + 1 1 1 1 1 1 1 1 0 1 0 0 0 + 1 1 1 1 1 1 0 1 0 0 0 + 1 1 1 1 1 1

x Stuff that is already known: MULTIPLICATION Single bit multiplication looks like this: 0 0 = 0 0 1 = 0 1 0 = 0 These are not AND operations!! But it acts like AND logic 1 1 = 1

x A quick example of BASE2 Multiplication: x 1 0 1 1 1 + 1 1 0 1 0 1 1 1 1 0 1 0

A quick example of BASE2 Division: 101 10010110 Since the divisor is a 3-bit number => From left-to-right, observe the first 3-bits 0 101 10010110 4 < 5; Quotient = 0. Add next bit 0 1 101 10010110 9 > 5; Quotient = 1. Multiply/Subtract. -101 Add the next bit. 1 0 0 0

0 1 1 101 10010110 8 > 5; Quotient = 1. Multiply/Subtract. -101 Add the next bit. 1 0 0 0-1 0 1 0 1 1 1 0 1 1 1 101 10010110 7 > 5; Quotient = 1. Multiply/Subtract. -101 Add the next bit. 1 0 0 0-1 0 1 0 1 1 1-1 0 1 0 1 0 1

0 1 1 1 1 101 10010110 7 = 7; Quotient = 1. Multiply/Subtract. -101 Add the next bit. 1 0 0 0-1 0 1 0 1 1 1-1 0 1 0 1 0 1-1 0 1 0 0 0 0

1 0 1 0 1 1 1 1 0 10010110-101 1 0 0 0-1 0 1 0 1 1 1-1 0 1 0 1 0 1-1 0 1 0 0 0 0 Quotient/Result 0 < 7; Quotient = 0. No more bits to add. Remainder

As seen on the multiplication and division examples it takes many steps to generate an output The more steps = more clock cycles on the machine/board Instructions like SHIFTING binary values helps reduce the # of steps Only two ways to shift: Left or Right When shifting by 1 to the left/right: the digits move one place on that direction You can shift by more than 1

Example of shifting a DECIMAL value: SHIFT LEFT Start with the value: 100 Shift left by 1 Shift left by 2 Shift left by 3 Add a zero: 1000 Add zeros: 10000 Add zeros: 100000 x10 x100 x1000

Example of shifting a DECIMAL value: SHIFT RIGHT Start with the value: 100 Shift right by 1 Shift right by 2 Shift right by 3 drop a zero: 10 Drop zeros: 1 Drop zeros: 0.1 10 100 1000

Example of shifting a BINARY value: SHIFT LEFT Start with the value: 11101 Shift left by 1 Shift left by 2 Shift left by 3 Add a zero: 111010 Add zeros: 1110100 Add zeros: 11101000 x2 x4 x8 11101 << 1 11101 << 2 11101 << 3

Example of shifting a DECIMAL value: SHIFT RIGHT Start with the value: 11101 Shift right by 1 Shift right by 2 Shift right by 3 drop LSB: 1110 Drop 2 LSBs: 111 Drop 3 LSBs: 11 2 4 8 11101 >> 1 11101 >> 2 11101 >> 3

http://thebeausejourpulpit.files.wordpress.com/2012/05/end-of-the-world.jpg