(Math)Texture Flags from a number

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

FlagDKT(Posted 2006) [#1]
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 :)


Finjogi(Posted 2006) [#2]
AND is your friend :)


FlagDKT(Posted 2006) [#3]
ehm...waht's the usage for that?


FlagDKT(Posted 2006) [#4]
if (11 and 2) then print "It's ALPHA"


I think it's right


kevin8084(Posted 2006) [#5]
***EDIT***** Removed by kevin8084 in favor of jfk's better illustration below.


kevin8084(Posted 2006) [#6]
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)



FlagDKT(Posted 2006) [#7]
thx Kevin, very useful :)


kevin8084(Posted 2006) [#8]
no problem


jfk EO-11110(Posted 2006) [#9]
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.