32x32 =32 multiplier

D

designer

Guest
Suppose I want to multiply 2 signed numbers (32 bit signed ints) and
the result is stored in 32 bits only.
So do I have to look at sign of each of the operand to decide the sign
of the result or just truncate the result to 32 bits. What is the
general funda of truncation...
Thanks In Advance
 
On Nov 26, 6:01 pm, designer <vittal.pa...@gmail.com> wrote:
Suppose I want to multiply 2 signed numbers (32 bit signed ints) and
the result is stored in 32 bits only.
So do I have to look at sign of each of the operand to decide the sign
of the result or just truncate the result to 32 bits. What is the
general funda of truncation...
Thanks In Advance
You usually multiply unsigned numbers. The truncation will get lower
32 bits only.
If you need a sign you can do it manually - it is very easy.
 
On Nov 25, 11:01 pm, designer <vittal.pa...@gmail.com> wrote:
Suppose I want to multiply 2 signed numbers (32 bit signed ints) and
the result is stored in 32 bits only.
So do I have to look at sign of each of the operand to decide the sign
of the result or just truncate the result to 32 bits. What is the
general funda of truncation...
Thanks In Advance
You can't. You can multiply 2 16-bit operands into 32 bits, but 2 32-
bit operands creates a 64-bit product.

I suppose you could just strip off the upper 32 bits; I suggest you
keep an overflow status somewhere.

Traditionally, the operands are made positive before the multiply.
The sign of the product is the XOR of the signs of the operands.

AL.
 
On Nov 26, 11:49 am, LittleAlex <alex.lo...@email.com> wrote:
On Nov 25, 11:01 pm, designer <vittal.pa...@gmail.com> wrote:

Suppose I want to multiply 2 signed numbers (32 bit signed ints) and
the result is stored in 32 bits only.
So do I have to look at sign of each of the operand to decide the sign
of the result or just truncate the result to 32 bits. What is the
general funda of truncation...
Thanks In Advance

You can't.  You can multiply 2 16-bit operands into 32 bits, but 2 32-
bit operands creates a 64-bit product.

I suppose you could just strip off the upper 32 bits; I suggest you
keep an overflow status somewhere.

Traditionally, the operands are made positive before the multiply.
The sign of the product is the XOR of the signs of the operands.

AL.
If you only want the low 32 bits of the result, then it doesn't matter
if the inputs were signed or not. Only the upper 32 bits depend on
the
sign. Determining overflow may be tricky if you don't use the
appropriate form of multiply, however.
 
On Nov 26, 9:05 am, gabor <ga...@alacron.com> wrote:
If you only want the low 32 bits of the result, then it doesn't matter
if the inputs were signed or not. Only the upper 32 bits depend on
the sign.
Not true.

All the bits (except the LSB) are different between 1 and -1.

AL
 
On Nov 26, 9:05 am, gabor <ga...@alacron.com> wrote:

If you only want the low 32 bits of the result, then it doesn't
matter if the inputs were signed or not. Only the upper 32 bits
depend on the sign.

Not true.

All the bits (except the LSB) are different between 1 and -1.

AL
Not true.

The exact representation of signed numbers wasn't given. It is true for
some representations of signed numbers.


---Matthew Hicks
 
LittleAlex wrote:

On Nov 26, 9:05 am, gabor <ga...@alacron.com> wrote:

If you only want the low 32 bits of the result, then it doesn't matter
if the inputs were signed or not. Only the upper 32 bits depend on
the sign.

Not true.

All the bits (except the LSB) are different between 1 and -1.
A better statement would be that:

Only the upper 32 bits depend on the signedness.

That is, the difference between a 32x32 signed multiple and unsigned
multiply is in the upper 32 bits.

-- glen
 
On Dec 1, 3:11 am, Glen Herrmannsfeldt <g...@ugcs.caltech.edu> wrote:
LittleAlex wrote:
On Nov 26, 9:05 am, gabor <ga...@alacron.com> wrote:
If you only want the low 32 bits of the result, then it doesn't matter
if the inputs were signed or not.  Only the upper 32 bits depend on
the sign.
Not true.
All the bits (except the LSB) are different between 1 and -1.

A better statement would be that:

    Only the upper 32 bits depend on the signedness.

That is, the difference between a 32x32 signed multiple and unsigned
multiply is in the upper 32 bits.

-- glen
Thank you, I was in fact assuming that inputs are two's complement
binary, so for instance -1 times -1 in the signed multiply gives
the same result for 32 LSB's as 32'hffffffff times 32'hffffffff
in the unsigned multiply. If you need to keep track of overflow,
however it is easier if the multiplier signedness matches the
signedness of the inputs.
 

Welcome to EDABoard.com

Sponsor

Back
Top