(Math)Texture Flags from a number

Blitz3D Forums/Blitz3D Programming/(Math)Texture Flags from a number

If I set 1+2+8 (11) to a TextureFlag, how could I extract those flags from 11?
I need to know if that texture is Alpha or not...
thx :)

AND is your friend :)

ehm...waht's the usage for that?

if (11 and 2) then print "It's ALPHA"


I think it's right

***EDIT***** Removed by kevin8084 in favor of jfk's better illustration below.

Boolean - Quick Primer
AND
A	B	Output = true(1) only if BOTH of the inputs are true
0	0	0
0	1	0
1	0	0
1	1	1

OR
A	B	Output = true(1) if either of the inputs are true
0	0	0
0	1	1
1	0	1
1	1	1

XOR
A	B	Output = true(1) only if either of the inputs are true, but not if BOTH are true
0	0	0
0	1	1
1	0	1
1	1	0


NAND (Not AND)
A	B	Output = false(0) only if BOTH of the inputs are true(1)
0	0	1
0	1	1
1	0	1
1	1	0

NOR (Not OR)
A	B	Output = true(1) only if BOTH of the inputs are false(0)
0	0	1
0	1	0
1	0	0
1	1	0

NOT
A	Output = opposite of input
0	1
1	0

Binary Shifts - just take the bits and shift them left or right the specified number of places
1024	512	256	128	64	32	16	8	4	2	1 = value of bits
----------------------------------------------------------------------------------------------------------------------------------------------
0	0	0	0	0	0	0	1	0	1	1  = 11
0	0	0	0	0	1	0	1	1	0	0  =  44 (11 shl 2)
0	0	0	1	0	1	0	0	0	0	0  =  160
0	0	0	0	0	1	0	1	0	0	0  =   40  (160 shr 2)


thx Kevin, very useful :)

no problem

kevins truth table is refering to bits, of course.

A practical use of AND may be

if (flags and 4)=4 then
print "mask flag set"
else
print "mask flag not set"
endif

if (flags and 2)=2 then
print "alpha flag set"
else
print "alpha flag not set"
endif

you could also ask if the result is other than zero, BTW.


what you do is:
(flag and 4)
will kill every bit other than the bit with the potential value 4. (that's the third bit on the right side.)

So if it is set, there will be a value of 4 remaining. Otherwise it will be zero.