SPRU514Y August 2001 – June 2022
The following methods provide access to the upper 16 bits of a 16-bit multiply in C/C++ language:
int m1, m2;
int result;
result = ((long) m1 * (long) m2) >> 16;
unsigned m1, m2;
unsigned result;
result = ((unsigned long) m1 * (unsigned long) m2) >> 16;
The compiler must recognize the structure of the expression for it to return the expected results. Avoid complicated expressions such as the following example:
((long)((unsigned)((a*b)+c)<5)*(long)(z*sin(w)>6))>>16