piclist 2001\04\01\201615a >
Thread: How to do 24bit Signed Addition/Substration Fixed point.
www.piclist.com/techref/microchip/devices.htm?key=pic
flavicon
face BY : James Lee Williams email (remove spam text)



So, you are saying that I can just use a flat ADD_24 through byte
carries reguard of the fact that one might be positive and one negative;
and the result would be the same as, I illustrated before?

All of my values will be positive until I try to subtract x1 from x2.
This cause it to go to negative.  Let me show you what my algorithm
looks like in c:
What is know is that x1,y1 and x2,y2 will always be positive.
Let x1 and y1 be the current position.

void MoveTo(x2,y2)
{
int y1,y2
int deltax = x2-x1;
int deltay = y2-y1;
//incredment or decrement direction of motion.
bool bIncX,bIncY;
if(deltax > 0)bIncX = true;
else bIncX = false;
if(deltay > 0)bIncY = true;
else bIncY = false;
if(deltax < 0) deltax = -deltax;
if(deltay < 0) deltay = -deltay;

int ax = << deltax;
int ay = << deltay;
int decx,decy;
//Now begin Bresenham Move
if(deltay > deltax)
{
 for(decy=ay-deltax;/**/;decy +=ay)
 {
   if(bIncX) x1++;
   else x1--;
   StepXY(x1,y1);
   if(x1==x2) break;
   if(decy >= 0)
   {
     decy -= ax;
     if(bIncY)y1++;
     else y1--;
   }
 }
}
else
{
 for(decx=ax-deltay;/**/;decx +=ax)
 {
   if(bIncY) y1++;
   else y1--;
   StepXY(x1,y1);
   if(y1==y2) break;
   if(decx >= 0)
   {
     decx -= ay;
     if(bIncY)x1++;
     else x1--;
   }
 }
}


{Original Message removed}
<03A1C3D564C54F41AE049A641BAE0D8A070E5D@infoexch01.infoserver.no> quoted-printable

See also: www.piclist.com/techref/microchip/devices.htm?key=pic
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) How to do 24bit Signed Addition/Substration Fixed point.

month overview.

new search...