Re: calculating an exponent?
From: Thad Smith (thadsmith_at_acm.org)
Date: 09/28/04
- Next message: Paul Lutus: "Re: calculating an exponent?"
- Previous message: Alf P. Steinbach: "Re: calculating an exponent?"
- In reply to: Jani Yusef: "Re: calculating an exponent?"
- Next in thread: Paul Lutus: "Re: calculating an exponent?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 28 Sep 2004 09:46:09 -0600
Jani Yusef wrote:
>
> Alf P. Steinbach wrote:
> > * Jani Yusef:
> >
> >>Is it possible to calculate an exponent, say, a^n, using only right
> >>and left shifts along with additions and subtractions?
> >
> > All arithmetic operations are implemented that way (in software or hardware).
> >
> > Presumably 'a' and 'n' are non-negative integers.
> >
> > The only question is then how (in)efficient you want the algorithm to
> > be. For efficiency it might be a good idea to first consider efficient
> > multiplication. With multiplication you can then tackle the efficiency of the
> > exponentiation, e.g. by noting treating odd n and even n differently.
>
> Hmmm, thats interesting but I am still confused as to how this is done?
> Suppose I want to calculate 2^5 , for example. What would the
> calculation look like. Would it be broken down first into
> 2*(2*2)*(2*2) ors omething like that? How is that different then, say,
> and even exponent? Sorry for all the questions but I really don't
> understand this at all.
Integer exponentiation can be done with a series of squaring and multiplication by the base. 2^5 = ((2^2)^2)*2. The
sequence of squaring and multiplication by the base is determined by the bits of the exponent expressed in binary.
Multiplication can be implemented with a sequence of shifts and conditional additions.
Thad
- Next message: Paul Lutus: "Re: calculating an exponent?"
- Previous message: Alf P. Steinbach: "Re: calculating an exponent?"
- In reply to: Jani Yusef: "Re: calculating an exponent?"
- Next in thread: Paul Lutus: "Re: calculating an exponent?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|