Author Topic: AND and OR  (Read 2126 times)

Thunor

  • Guest
AND and OR
« on: 2008-Jan-07 »
Hi

I saw your GP2X competition so I thought I'd try GLBasic :)

I have found the documentation (via Help) for AND and OR to be rather confusing. The documentation examples are using AND and OR as logical and bitwise operators, when in fact they only work as logical operators with bAND and bOR being responsible for bitwise operations.

Documentation for AND and OR :-
Quote
a# = b# AND c#
a# = b# OR c#

Binary operators. Mostly used for IF expressions.

AND:

Binary code of b#: 00100010
Binary code of c#: 00100100
Binary code of a#: 00100000
Only bits that are available in b# AND c# will be set in a#.

OR:

Binary code of b#: 00100010
Binary code of c#: 00100100
Binary code of a#: 00100110
All bits that are available in b# OR c# will be set in a#.
My GLBasic test results :-

133 AND 0x7F = 1 (this is returning TRUE so it is LOGICAL AND)
bAND(133, 0x7F) = 5 (this is the result of a bitwise operation)
5 OR 0x80 = 1 (this is returning TRUE so it is LOGICAL OR)
bOR(5, 0x80) = 133 (this is the result of a bitwise operation)

So therefore in GLBasic, AND and OR are exclusively LOGICAL as far as I can tell. a# will only ever be 0 or 1 in your examples above. No other bits will be set.

Regards

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10760
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
AND and OR
« Reply #1 on: 2008-Jan-07 »
Thank you. The docs are wrong.