Do variable equal to each of these numbers?
Hey guys,
If I want to check if a variable equal to 1 of for example 10 numbers, I think doing: if ( var == 5 || var == 6 || var == 7 ..... ) because then it would be hell long, and if I needed to check 50 numbers? so... I was wondering. Is it possible to do: new var = ( 1 | 2 | 3 ) if ( 2 & var ) or something like that? help me out here :X |
Re: Do variable equal to each of these numbers?
if( 1 <= var <= 50 )
This is the same as if( var == 1 || var == 2 || var == 3 || ... || var == 50 ) |
Re: Do variable equal to each of these numbers?
Quote:
my question is, is it possible to do new var = ( 1 | 2 | 3 ) new cmp = 2 if I do... if ( cmp & var ) will it be true? |
Re: Do variable equal to each of these numbers?
PHP Code:
PHP Code:
|
Re: Do variable equal to each of these numbers?
Quote:
|
Re: Do variable equal to each of these numbers?
Quote:
PHP Code:
PHP Code:
|
Re: Do variable equal to each of these numbers?
NVM GOT IT, it must be with the (1 << X), thanks exolent :)
|
Re: Do variable equal to each of these numbers?
Quote:
CL_CONNECTED = 1 CL_BOT = 2 CL_INGAME = 3 The problem is that 3 contains 2 and 1 (if you understand how bits work). 1 | 2 = 3 Therefore, checking CL_INGAME is checking CL_CONNECTED|CL_BOT, which is wrong. CL_INGAME should be 4, not 3. |
Re: Do variable equal to each of these numbers?
Quote:
|
Re: Do variable equal to each of these numbers?
Quote:
Quote:
|
| All times are GMT -4. The time now is 07:48. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.