Multiplying two shorts...

The Beach Bum jfh at rpp386.UUCP
Wed Aug 17 23:38:05 AEST 1988


In article <576 at proxftl.UUCP> bill at proxftl.UUCP (T. William Wells) writes:
>What this means is that if the product of the values of the two
>shorts will fit in an int, the code will work as expected.  If
>not, then the result IS undefined.

since this discussion orginally involved 16x16=32 multiply instructions,
i thought it might be nice to point out that any two 16 bit numbers can
be multiplied, and the result will always fit in 32 bits, without 
overflow.

unsigned:	FFFF x FFFF = FFFE0001
signed:		7FFF x 7FFF = 3FFF0001
-- 
John F. Haugh II                 +--------- Cute Chocolate Quote ---------
HASA, "S" Division               | "USENET should not be confused with
UUCP:   killer!rpp386!jfh        |  something that matters, like CHOCOLATE"
DOMAIN: jfh at rpp386.uucp          |         -- apologizes to Dennis O'Connor



More information about the Comp.lang.c mailing list