While I have your attention, I'm puzzling over how to efficiently do a 10-bit by 10-bit division (which will yield a value 0<x<1) then multiply it again by 1023 to get a number (0<=x<=1023). I'd prefer not to use LONG values as they eat up precious RAM, but I also want to keep it reasonably quick. I have plenty of words set up, but no LONGs.
Here's the math:
a, b, and x are WORDs
x=1023*(a-b)/(a+b)
Any thoughts?
EDIT: Oh. Ha ha. I don't even have LONGs to work with. Yeah... that makes a difference now, doesn't it?
The only thing I can conceive of is using a two-fold mechanism that combines this:
Code:
'Shift RESULT left 10 times
FOR Iter=1 to 10
RESULT=RESULT<<1
NEXT
with this:
Code:
'RESULT= B / A
RESULT=0
WHILE B>A
B=B-A
RESULT=RESULT+1
WEND
The trick is to keep the working value inside 16-bits, but inside 10 bits at the very end.
Bookmarks