Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Explanation for the basics of datatypes

Status
Not open for further replies.

patan.gova

Full Member level 3
Full Member level 3
Joined
Dec 19, 2011
Messages
172
Helped
4
Reputation
8
Reaction score
0
Trophy points
1,296
Visit site
Activity points
2,776
Hello,

I am new to the microcontrollers and want to know the working of the below two functions for the mutliplication of two 16bit numbers, if the 16bit microcontroller is used

Code:
Multilication function1
int32_t z; 
z=mutliplication ( 0x1234, 0x5678); 
return  z >> 15;

Multilication function2
signed long z;  
RESLO and RESHI =mutliplication ( 0x1234, 0x5678); //if results are stored in two different variables of 16bits(RESLO=lower,RESHI=higher)
z = RESHI;                          
z = (result<<16)|RESLO;             

Can someone explain me thw working of above lines.

thanks.
 

hello

this is my understanding ...

Code:
Multilication function1
int32_t z; 
z=mutliplication ( 0x1234, 0x5678); 
return z >> 15;

Z shifted right 15 times...
i don't know why result of muttiplication is divided by 2^15 (/ 32768)
if you want to get the sign
return z>>31 most significatif bit is the sign 1=Negativ 0 Positive


Code:
Multilication function2
signed long z; 
RESLO and RESHI =mutliplication ( 0x1234, 0x5678); //if results are stored in two different variables of 16bits(RESLO=lower,RESHI=higher)
z = RESHI; 
z = (result<<16)|RESLO;

Bad results !

from where do you find "result" variable ?

Code:
z =mutliplication ( 0x1234, 0x5678)
RESHI=(int16) ( z>>16);
RESLO=( int16 ) (z & 0x0000FFFF);
 

sorry,
I made a mistake while writing and it should be should 'z' instead of 'result' as this
signed long z;
RESLO and RESHI =mutliplication ( 0x1234, 0x5678); //if results are stored in two different variables of 16bits(RESLO=lower,RESHI=higher)
z = RESHI;
z = (z<<16)|RESLO;
 

And also which line says so "result of multiplication is divided by 2^15 (/ 32768)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top