Subject: The base case of multiply

From: Archisman Rudra <[email-masked]>
Date: Tue, 9 Nov 1999 21:38:48 -0500 (EST)

Dear Class,
      Many people have had this problem: What exactly do you check in
the base case:  This is a multi-step procedure:

     Base case kicks in when either n1 or n2 has bitLength of 1.
In either of these cases, you should check to see what the least
significant bit of that argument is. If this is 1, the relevant argument
is 1, and you return the other argument; if this is 0, the product
is surely 0, and you return BigInteger.ZERO....

    How to check for this bit:

    Take a look at testBit function ....

    testBit(0) of the appropriate object is your friend here....

-- Archi

---

From: Chee Yap <[email-masked]>
Date: Wed, 10 Nov 1999 09:01:26 -0500 (EST)

Correction to the message below:

The base case should be for bitLengths AT MOST 1.
So you should check for bigLength of 0 as well as 1.

Of course, bitLength is 0 iff the number is 0. This case
could happen even if your original inputs are strictly positive!
To see this, if X is much smaller than Y, then when you
split X into X0 and X1, we may have X1 = 0.

Of course, you could check if X1 is 0 before doing the
recursive calls, but this is more complicated than
allowing your multiplication algorithm to accept 0 as an argument.

--Chee

> From [email-masked] Tue Nov  9 21:39 EST 1999
> X-Authentication-Warning: slinky.cs.nyu.edu: archi owned process doing -bs
> Date: Tue, 9 Nov 1999 21:38:48 -0500 (EST)
> From: Archisman Rudra <[email-masked]>
> To: [email-masked]
> Subject: The base case of multiply
> 
>   Dear Class,

---

From: Chee Yap <[email-masked]>
Date: Wed, 10 Nov 1999 13:24:58 -0500 (EST)

Aditi:

yes, that is correct.
You can test this out by
writing a small Java program!

Chee

> From [email-masked] Wed Nov 10 12:19 EST 1999
> X-Sender: [email-masked]
> Date: Wed, 10 Nov 1999 12:20:18 -0500
> To: Chee Yap <[email-masked]>
> From: Aditi Sheth <[email-masked]>
> Subject: Re: The base case of multiply
> 
> Dear Prof. Yap,
> 
> I am a little confused with your e-mail: 
> does that mean that if the bitlength is 0, then the number is necessarily
> 0, and so, if the bit length is 1, then the number is necessarily 1 (and
> not 1 or 0)?
> Thank you,
> Aditi Sheth
> 
> At 09:01 AM 11/10/99 -0500, you wrote: