OR ???

Blitz3D Forums/Blitz3D Programming/OR ???

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Anthony is right. OR works by setting the bits corresponding to its arguments. It is NOT an addition type command. For ex., 3+1 = 4, is not the same as 3 OR 1 (which is 3) it sets the bit you tell it to set.

EX. 3 + 1 = 4

00000011 (3)
+ 00000001 (1)
==============
00000100 (4)

in "OR" it's: 3 OR 1 = 3

00000011 (3)
OR 00000001 (1)
===============
00000011 (3) since the 0 bit was already set, no different outcome...

here's the diff: 2 OR 1 = 3

00000010 (2)
OR 00000001 (1)
===============
00000011 (3)

The 0 bit get's set and the resulting number is 3.

That's why it is so convenient to use it to set bits (flags, in most cases ordered within a byte as powers of 2).

If you use XOR, it toggles the bits in question.
(Good for figuring out if an item is in use, or something's status has been changed in a game)

The above is the bitwise OR, the logical OR usually evaluates down to some values being tested and the condition being true if any of the values evaluate to true. (like in an IF a or b then...) It comes down to a boolean and if any of the booleans are true the condition is met and execution branches accordingly. (See DrakeX's example)