AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with a bit-field (https://forums.alliedmods.net/showthread.php?t=164659)

Kiske 08-14-2011 08:29

Help with a bit-field
 
Hi.

It's my first time using bits.
I wanted to know how to do this:
PHP Code:

#define set_user_bit(%1, %2)     (%2 |= (1 << (%1 & 31)))
#define clear_user_bit(%1, %2)     (%2 &= ~(1 << (%1 & 31)))
#define has_user_bit(%1, %2)     (%2 & (1<< (%1 & 31)))

if(has_user_bit(idg_data[MD])) set_user_bit(idg_data[MD]);
else 
clear_user_bit(idg_data[MD]); 

but a simpler way like this:
PHP Code:

g_data[id] = !g_data[id]; 


Another question,
PHP Code:

g_data[id] = var; 

I can do this bit ?

Thanks in advance.

ConnorMcLeod 08-14-2011 08:59

Re: Help with a bit-field
 
- you can use the simpler way
- no you can't, bit can only handle bools (0 or 1 vars).

Kiske 08-14-2011 10:07

Re: Help with a bit-field
 
Quote:

Originally Posted by ConnorMcLeod (Post 1532316)
- you can use the simpler way
- no you can't, bit can only handle bools (0 or 1 vars).

Ok, thanks :)


All times are GMT -4. The time now is 03:31.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.