Force bitwise operation to return only 0 or 1
#1

Hi there. I'm debugging some stuff, and I'm using bitflags to speed up the process. Take a look:

pawn Код:
new test = 8, Float:b = 79.5;
new a = (test & 8);
Well, nope, this returns me 8. Now I've tried
pawn Код:
new a = _:(test & 8 > 0);
Cool, it works, but I don't want to rewrite it each time I use a flag.
pawn Код:
new a = (test & 8 % 2);
Is there some magic bitoperator which will return me 1 if flag is present and 0 if not? (I'm not talking about bool, but integer/tagless number)

#e: nope, the second method isn't even supposed to work
Reply
#2

pawn Код:
new a = !!(test & 8);
That should work. Though I don't really understand why you would want to get 1 and 0 instead of true and false.
Reply
#3

Nope, I use the double negation as anything-to-bool converter, so tag mismatch

Why value? I used to write
pawn Код:
new value = 5 * (flag & 8 ? 1 : 0)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)