Shop OBEX P1 Docs P2 Docs Learn Events
Working with binaries — Parallax Forums

Working with binaries

fzrobotfzrobot Posts: 7
edited 2007-02-19 18:35 in BASIC Stamp
Ok, so who else thinks this is weird?

Let's say I have a signed binary number coming from a device into the stamp via

SHIFTIN  Dio, Clk, MSBPOST,  [noparse][[/noparse]VRefCount\13]
...
SHIFTIN  Dio, Clk, MSBPOST,  [noparse][[/noparse]axisCount\13] 




then I subtract them (as an example take my values: axisCount=0000100111001111 VRefCount = 0000011111111110)

subtraction = axisCount - VrefCount




And for the sake's of the argument let's assume that axisCount is ALWAYS greater than VrefCount.

Then, this is my "problem":

If I do the conditional:

  IF (subtraction>800) THEN
  DEBUG "The conditional is true"
  GOTO Main
  ENDIF




it evaluates to a true statement for the numbers I presented above (and thus, it prints "The conditional is true").

However, if I (without changing or touching anything on the Boe-Bot) do this "minor" change

  IF ((subtraction>800)|(subtraction<300) THEN
  DEBUG "The conditional is true"
  GOTO Main
  ENDIF




then all of the sudden it evaluates to a false statement (it doesn't print the line)

Anybody finds this weird?

Thanks,

-Cisco

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-02-19 16:42
    Cisco -

    It appears you want to use a LOGICAL AND and not a BITWISE AND. The former is a LOGICAL operation and the latter is an ARITHMETIC operation. Make the following change:

    From -

    IF ((subtraction>800)|(subtraction<300) THEN

    To:

    IF ((subtraction>800) and (subtraction<300) THEN

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • fzrobotfzrobot Posts: 7
    edited 2007-02-19 18:35
    hehe... That did it (feeling kinda dumb, but I figured that I was doing something silly like that).

    Thanks, btw, | is bitwise OR, so I just changed it for the "OR" binary operator to do what I intended.

    Thanks again.

    Cheers,

    -Cisco
Sign In or Register to comment.