Go to Post A robot is never "complete" - [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #12   Spotlight this post!  
Unread 29-04-2003, 12:47
Joe Johnson's Avatar Unsung FIRST Hero
Joe Johnson Joe Johnson is offline
Engineer at Medrobotics
AKA: Dr. Joe
FRC #0088 (TJ2)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Raynham, MA
Posts: 2,648
Joe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond repute
And one more thing...

Oh yeah, I forgot to answer the basic question from this tread.

If you want to accomplish the equiv. of (Var = XXX) you can do this:

bitvarY = (bytevarX = 254)

You can do this:

bitvarY = 1 - (- ABS(bytevarX - 254) >> 15 )

Again, this is ugly but it accomplishes the result you want without an IF statement.

If you are looking to minize code size you may want to try NCD

bitvarY = 1 - (- NCD(bytevarX - 254) >> 15)

Another hack to try would be to use bitwize XOR for your compare test -- thinking about it, this may be the fastest and tightest way to do it;

bitvarY = 1 - ( - (bytevarX ^ 254) >> 15)

Yet another thing to try is the Pbasic's normal truncation and the REV function rather than the "-" sign and the ">> 15" business. The whole purpose of these things is to take advantage of all numbers but zero have a negative with a 1 in the high order bit of a 16 bit number.

You can get t this bit in an expression using the following as well:

bitvarY = ( - (bytevarX ^ 254) REV 16)

The above also reverses the sense of bitvarY. It becomes 1 in they are different and 0 if they are equal.

This brings up another simplification. Changing bitvarY to the opposite sense (bytevarX <> 254) makes the test a bit easier to implement as all the "1 -" s from the above expressions disappear.

Hope this helps.

Joe J.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
BS2 syntax (PBASIC) on the new controllers? Maybe! Jeremy_Mc Programming 0 25-10-2003 15:00
PBASIC Syntax Question Raven_Writer Programming 4 20-08-2003 08:07
Pbasic 2.5 syntax Rickertsen2 Programming 10 15-02-2003 08:56
Another PBASIC Question Ian W. Programming 4 31-01-2002 21:36
Simplifying PBasic IDiggles General Forum 16 06-11-2001 01:36


All times are GMT -5. The time now is 19:39.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi