with more bells and whistles
with more bells and whistles
Last edited by richard; - 16th September 2015 at 06:59.
Hi guys,
I hope i'm not hijacking this thread but...
Maybe my mind is set to work with decimal only and this might be a dumb question but i cant understand what we can get from these operationsIt's not complicated...
C=A*/B is same as C=(A*B)/$FF
C=A**B same as C=(A*B)/$FFFF
If A=1234 and B=5678 then
A*B=7006652 ( which in bynary is 0110 1010 ... )
I know that this operation keeps the higher 2 bytes 0110 1010 so
A**B= 106
Having said that, i know how they work... so my question is, when and why are these operations used?
Thanks
its mainly about speed of execution and code size.
eg miles to kilometre conversion k=m*1.609
pbp has no floats so the 1.609 needs to be scaled up and then the result scaled back
this will work :-
you could do 1.609*1000=1609
k=m*1609 /1000
(k=m*1609
div32 1000)
this is better :-
using 1.609 * 256 = 411
so k=m*411/256 (eq to k=m*/411)
and will give you smaller faster code
and has a larger input range before overflowing also
Thanks for the explanation Richard,
It's crystal clear now
Regards
Rui
Bookmarks