![]() |
Detecting multiple values in a bitflag
Is there any other way to test for multiple values in a bitflag other than iterating through it?
|
if (flags & (flag1 | flag2))
|
Quote:
you could have 100000000000000000000000000000001 or 000000000000000010000000000000000 I mean, of course I would know the range of this flag. it certainly wouldn't take all 32 places. What would be the best way to detect if there is more than one value stored in it though? for (i=0; i<flagsize; i++) { if (flag & 2^i) this.flagcounter++; if (this.flagcounter == 2) return true; } return false; |
First of all, Graal doesn't support above 32bits for numbers (I think).
Second, what I said was correct if (flags & (0x100000001 | 0x10000)) [edit] We had a discussion about this on IRC and we came to that I misunderstood your original question, mostly because your original question was not written very well. Anyway, my point of view: you're using bitflags for the wrong reason. But uhh, here's how I would do it: PHP Code:
|
I'm using bit flags to conserve variable space actually.
|
You need to loop through all bits you want to check, there is no countbits() function or so yet
|
ok
|
| All times are GMT +2. The time now is 12:51 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.