|= and &
#9

Example, using two cases.

I've a variable, to identify somethings about my personality on the game.
Код:
new person[MAX_PLAYERS];
And I've mapped it on 2 bits, the 1st bit indicates that I'm an admin player, the 2nd bit indicates that I'm a vip player.

So, I can create macros for indentify the difference between vp and ap:
pawn Код:
#define ADMIN_P 0b01
#define VIP_P 0b10
And I can set it, just using:
pawn Код:
person[playerid] |= ADMIN_P;
Now I set myself as an administrator.

to verify, you can use AND bit operator:
pawn Код:
if (person[playerid] & ADMIN_P) //indicates that I'm an Administrator
if (person[playerid] & VIP_P) //indicates that I'm a vip player, but it will return false (01 & 10 = 00)
Reply


Messages In This Thread
|= and & - by iBots - 08.01.2015, 21:29
Re: |= and & - by DavidSparks - 08.01.2015, 21:30
Re: |= and & - by Schneider - 08.01.2015, 21:32
Re: |= and & - by DavidSparks - 08.01.2015, 21:32
Re: |= and & - by WLSF - 08.01.2015, 21:36
Re: |= and & - by Mauzen - 08.01.2015, 21:43
Re: |= and & - by iBots - 08.01.2015, 21:52
Re: |= and & - by iBots - 08.01.2015, 22:00
Re: |= and & - by WLSF - 08.01.2015, 22:01
Re: |= and & - by Vince - 08.01.2015, 22:02

Forum Jump:


Users browsing this thread: 2 Guest(s)