Force bitwise operation to return only 0 or 1 - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Force bitwise operation to return only 0 or 1 (
/showthread.php?tid=423802)
Force bitwise operation to return only 0 or 1 -
Misiur - 19.03.2013
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.
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
Re: Force bitwise operation to return only 0 or 1 -
Vince - 19.03.2013
That should work. Though I don't really understand why you would want to get 1 and 0 instead of true and false.
Re: Force bitwise operation to return only 0 or 1 -
Misiur - 19.03.2013
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)