Raise a number x to the power y

Slides:



Advertisements
Similar presentations
1 Computational Complexity Size Matters!. 2 Suppose there are several algorithms which can all be used to perform the same task. We need some way to judge.
Advertisements

2.2 General Positional-Number-System Conversion
Binary & Decimal numbers = 3* * *10 + 5*1 = 3* * * *10 0 Decimal system: Ten digits: 0,1,2,3,…,9 Example:
Assembly Language and Computer Architecture Using C++ and Java
Assembly Language and Computer Architecture Using C++ and Java
Mathematics with Binary. Question  Below is a binary string  Which is the least significant bit (LSB)?  Which is the most significant bit (MSB)? 0.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
1 Number Systems. 2 Numbers Each number system is associated with a base or radix – The decimal number system is said to be of base or radix 10 A number.
Number Systems and Arithmetic
They are the same as registers since they store binary numbers. Called shifting registers since they shift (left or right) the binary number stored in.
Converting binary to decimal decimal to binary
Revision Introductory Lesson
Arithmetic.
Binary and Hexadecimal Numbers
Number Systems.
L e a s t C o m m o n M u l t I p l e.
Number Systems Binary and Hexadecimal. Base 2 a.k.a. Binary  Binary works off of base of 2 instead of a base 10 like what we are taught in school 
Estimating Square Roots to the Tenths and Hundredths Place.
Comp Sci 251 Intro 1 Computer organization and assembly language Wing Huen.
Number systems, Operations, and Codes
Number Base Conversions
Number Systems Binary to Decimal Octal to Decimal Hexadecimal to Decimal Binary to Octal Binary to Hexadecimal Two’s Complement.
AEEE2031 Data Representation and Numbering Systems.
 What are exponents?  Exponents are numbers that show how many times a base is used as a factor.  How do we use exponents?  Exponents will tell us.
Two’s Complement. A system used to represent a negative number in binary A system used to represent a negative number in binary Positive numbers start.
Binary01.ppt Decimal Decimal: Base 10 means 10 Unique numerical digits ,00010,000 Weight Positions 3,
Number Representation Lecture Topics How are numeric data items actually stored in computer memory? How much space (memory locations) is.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Logic Design Dr. Oliver Faust.
Computer Number System
Chapter 1 Number Systems Digital Electronics. Topics discussed in last lecture Digital systems Advantages of using digital signals over analog. Disadvantages.
Martin-Gay, Beginning Algebra, 5ed EXAMPLE Simplify the following radical expression.
The Hexadecimal System is base 16. It is a shorthand method for representing the 8-bit bytes that are stored in the computer system. This system was chosen.
MULTIPLYING DECIMALS Sixth Grade Math August 20, 2013.
Number Systems and Binary Arithmetic Quantitative Analysis II Professor Bob Orr.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
Презентацию подготовила Хайруллина Ч.А. Муслюмовская гимназия Подготовка к части С ЕГЭ.
Binary Number System And Conversion
Binary & Decimal numbers
Numbering Systems.
The Binary Number System and Conversions
CHAPTER 1 : INTRODUCTION
Rules of Exponents Multiplying and powers
Number Systems.
Tutorial 7.
Digital Electronics Number Systems and Codes
Writer:-Rashedul Hasan. Editor:- Jasim Uddin
Binary Number System And Conversion
Binary Number System And Conversion
Number System conversions
Binary Number System And Conversion
Number Systems and Binary Arithmetic
Integers in 2’s compliment Floating point
LF - EN Memory EM4056 Memory EM4056 and its security J.-D. Chatelain.
The Binary Number System and Conversions
1. Number Systems.
Completing the Square.
“Human Sorting” It’s a “Problem Solving” game:
Binary Number System And Conversion
Square Root.
Chapter 2: Number Systems
Number Systems Rayat Shikshan Sanstha’s
Binary Addition (1 of 2) Two 1-bit values A B A + B 1
Binary to Decimal Conversion
Number Systems Rayat Shikshan Sanstha’s
Lecture No.5.
Binary Number System And Conversion
“Human Sorting” It’s a “Problem Solving” game:
Binary Number System And Conversion
Lecture 9: Shift, Mult, Div Fixed & Floating Point
Presentation transcript:

Raise a number x to the power y

Raise a number x to the power y Example: 645

Raise a number x to the power y Example: 645 6*6*6*6*6*...*6 Yikes! 45 multiplies

Raise a number x to the power y Example: 645 6*6*6*6*6*...*6 Yikes! 45 multiplies 6 = n[0] (61) n[0]*n[0] = n[1] (62) n[1]*n[1] = n[2] (64) n[2]*n[2] = n[3] (68) n[3]*n[3] = n[4] (616) n[4]*n[4] = n[5] (632) So, 645 = n[5]*n[3]*n[2]*n[0] Only 8 multiplies!

Raise a number x to the power y Example: 645 Notice: 645 = 6101101 (in binary) 6 = n[0] (61) n[0]*n[0] = n[1] (62) n[1]*n[1] = n[2] (64) n[2]*n[2] = n[3] (68) n[3]*n[3] = n[4] (616) n[4]*n[4] = n[5] (632) So, 645 = n[5]*n[3]*n[2]*n[0]

Raise a number x to the power y Example: 645 Notice: 645 = 6101101 (in binary) Also notice: x1000 is the square of x100 and x1010100 is the square of x101010

Raise a number x to the power y Example: 645 Notice: 645 = 6101101 (in binary) Algorithm: Find binary equivalent of y. Define an accumulator variable p and initialize it to x. Starting with the 2nd most significant bit of y, repeat the following until all bits of y are considered: Square p. If the bit is 1, multiply p by x. Consider the next lesser significant bit of y.

Raise a number x to the power y Example: 645

Raise a number x to the power y Example: 645 So: x = 6, y= 45 = 101101 (in binary)

Raise a number x to the power y Example: 645 So: x = 6, y= 45 = 101101 (in binary) Set p = 6

Raise a number x to the power y Example: 645 So: x = 6, y= 45 = 101101 (in binary) * Set p = 6 2nd MSB of y is 0 so square p (p = 36)

Raise a number x to the power y Example: 645 So: x = 6, y= 45 = 101101 (in binary) * Set p = 6 2nd MSB of y is 0 so square p (p = 36) Next MSB is 1: square and mult (p = 7776)

Raise a number x to the power y Example: 645 So: x = 6, y= 45 = 101101 (in binary) * Set p = 6 2nd MSB of y is 0 so square p (p = 36) Next MSB is 1: square and mult (p = 7776) Next MSB is 1: square and mult (p = 362797056)

Raise a number x to the power y Example: 645 So: x = 6, y= 45 = 101101 (in binary) * Set p = 6 2nd MSB of y is 0 so square p (p = 36) Next MSB is 1: square and mult (p = 7776) Next MSB is 1: square and mult (p = 362797056) Next MSB is 0: square (p = 131621703842267136)

Raise a number x to the power y Example: 645 So: x = 6, y= 45 = 101101 (in binary) * Set p = 6 2nd MSB of y is 0 so square p (p = 36) Next MSB is 1: square and mult (p = 7776) Next MSB is 1: square and mult (p = 362797056) Next MSB is 0: square (p = 131621703842267136) Last MSB is 1: s&m (p = 103945637534048876111514866313854976)

Raise a number x to the power y Example: 645 How to find the last MSB?

Raise a number x to the power y Example: 645 How to find the last MSB? 101101 *

Raise a number x to the power y Example: 645 How to find the last MSB? 101101 * (45 % 2)

Raise a number x to the power y Example: 645 How to find the last MSB? 101101 * (45 % 2) How to strip off the last MSB?

Raise a number x to the power y Example: 645 How to find the last MSB? 10110 1 * (45 % 2) How to strip off the last MSB? (45 / 2)

Raise a number x to the power y Example: 645 How to find the last MSB? (45 % 2) How to strip off the last MSB? (45 / 2) How to store all the bits? Work from LSB to MSB and put the bits on a stack.