 Login Join Maker Pro

### Network # 2's Complement Multiply with Constant

D

#### Davy

Jan 1, 1970
0
Hi all,

I have 2's Complement digit range from negtive to positive. How to
multiply it with a constant?

Now, I have to turn 2's complement to signed-digit format and do

And there is a big problem confused me a long time:
Is there any method have the merits from signed-digit(easy to multiply)
and 2's complement(easy to add)?

Any suggestions will be appreciated!
Best regards,
Davy

K

#### Ken Smith

Jan 1, 1970
0
Hi all,

I have 2's Complement digit range from negtive to positive. How to
multiply it with a constant?

Now, I have to turn 2's complement to signed-digit format and do

And there is a big problem confused me a long time:
Is there any method have the merits from signed-digit(easy to multiply)
and 2's complement(easy to add)?

Imagine a 16 bit 2's compliment number. The LSB has a value of 1, the
next is 2 ... etc ... 16384. The top bit has a value of -32768.

S

#### [email protected]

Jan 1, 1970
0
Davy said:
Hi all,

I have 2's Complement digit range from negtive to positive. How to
multiply it with a constant?

Now, I have to turn 2's complement to signed-digit format and do

And there is a big problem confused me a long time:
Is there any method have the merits from signed-digit(easy to multiply)
and 2's complement(easy to add)?

I'm assuming doing this on platforms without a hardware multiplier or a
multiply instruction. Otherwise multiplying with a constant is the same
as multiplying with a variable.

In which case, I don't get it. 2's complement is as easy to multiply as
it is to add. There's no need to convert it to signed digit first.

Lets look at some examples of 2's complement multiplication of negative
numbers, we'll stick to 8 bits to make it short:

-1 * 2 = -2
11111111 (-1, shift left by 1 to multiply by 2)
11111110 (equals -2)

-5 * 4 = -20
11111011 (-5 shift left by 2 to multiply by 4)
11101100 (equals -20)

-3 * 5 = -15
11111101 (-3 shift left by 2 to multiply by 4)
11110100 (equals -12 add -3)
11110001 (equals -15)

In none of the examples above do I need to convert to signed digit. If
multiplying by a negative constant, then simply use the positive
version of the constant and 2's complement the variable before
multiplying (in effect multiplying it by -1):

1 * -2 = -2
00000001 (1, 2's complement to multiply by -1)
11111111 (-1, shift left to multiply by 2)
11111110 (equals -2)

-1 * -2 = 2
11111111 (-1, 2's complement to multiply by -1)
00000001 (1, shift left to multiply by 2)
00000010 (equals 2)

I don't get what you're complaining about.

B

#### Ben Rudiak-Gould

Jan 1, 1970
0
Davy said:
I have 2's Complement digit range from negtive to positive. How to
multiply it with a constant?

Fixed-width 2's complement multiplication is the same as fixed-width
unsigned multiplication. Just pretend you're doing unsigned multiplication;
it'll work even if the value is negative.

(This does not apply if you want a result larger than the operands, though.)

-- Ben

R

#### RED

Jan 1, 1970
0
Well you can do the sign extension of this "signed number" by the
number of bits of the constant and then simple multiply.. i am assuming
the constant to be a positive number. You can use the concept of adding
the signed numbers (thats easy in 2's compliment) for multiplication...
See the cases of overflow and avoid it..

C

#### Charles Marslett

Jan 1, 1970
0
Fixed-width 2's complement multiplication is the same as fixed-width
unsigned multiplication. Just pretend you're doing unsigned multiplication;
it'll work even if the value is negative.

(This does not apply if you want a result larger than the operands, though.)

-- Ben

And of course if you do want the double size product, just remember
that the 2-s compliment number is the same as (-2^n)+unsignedNum, so
you can just subtract the other number in the upper half of the
product:

That is, if you have an unsigned product A*B=[C ] with A, B, C and D
all n bits long, if A is signed and B is not, the product is [C-B ]
and if both are signed, then it is [C-A-B ].

--Charles

Replies
3
Views
2K
Replies
4
Views
995
Replies
5
Views
2K
B
Replies
2
Views
894