Raised This Month: $32 Target: $400
 8% 

[INFO] Bitsums and Operators


Post New Thread Reply   
 
Thread Tools Display Modes
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 04-20-2009 , 13:43   Re: [INFO] Bitsums and Operators
Reply With Quote #31

Quote:
Originally Posted by Exolent[jNr] View Post
Ahem, andrade.
"continue" is never called because the if() statement never returns true.

Code:
array[32] = false bitsum &= ~(1<<32)
Dear Exolent you are right. So the code do not match the profile.
__________________
joaquimandrade is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 04-20-2009 , 15:23   Re: [INFO] Bitsums and Operators
Reply With Quote #32

If I have
Code:
(1<<CSW_*)
Is there a way to get the CSW_* ?
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 04-20-2009 , 16:58   Re: [INFO] Bitsums and Operators
Reply With Quote #33

If you were doing this in x86 assembly you'd use the bsr (bit search right) instruction.
In pawn I guess your best bet is looping and dividing by two (or shifting right by one) until the number becomes 0, and counting the number of divisions/shifts performed.
__________________
hello, i am pm
PM is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-20-2009 , 17:57   Re: [INFO] Bitsums and Operators
Reply With Quote #34

Yep, I know only this way : do ++x; while ( ( bitsum /= 2 ) >= 1 )
Arkshine is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 04-20-2009 , 18:05   Re: [INFO] Bitsums and Operators
Reply With Quote #35

PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN    "New Plugin"
#define AUTHOR    "Unknown"
#define VERSION    "1.0"

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)    
    
register_clcmd("some","some");    
}

public 
some(id)
{
    new 
value[]  = << 20 << 13 << 29
    
    
for(new i=0;i<4;i++)
    {
        if(
value{i})
        {
            for(new 
j=0;j<8;j++)
            {            
                if(
value{i} & (<< j))
                {
                    
client_print(id,print_chat,"Has (1 << %d)",(8*(i)) + j)
                }
            }
        }
    }

or

PHP Code:
public some(id)
{
    new 
value[]  = ~(<< 29)
    
    for(new 
i=0;i<4;i++)
    {
        if(
value{i})
        {
            for(new 
j=7;j>=0;j--)
            {            
                if(
value{i} & (<< j))
                {
                    
client_print(id,print_console,"Has (1 << %d)",(8*(3-i)) + j)
                }
            }
        }
    }

or

PHP Code:
public some(id)
{
    new 
value[]  = ~(<< 3)
    
    new 
index
    
    
for(new i=3;i>=0;i--)
    {
        if(
value{i})
        {
            for(new 
j=0;j<=7;j++,index++)
            {            
                if(
value{i} & (<< j))
                {
                    
client_print(id,print_console,"Has (1 << %d)",index)
                }
            }
        }
        else
            
index += 8;
    }

__________________

Last edited by joaquimandrade; 04-20-2009 at 19:38.
joaquimandrade is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-20-2009 , 21:49   Re: [INFO] Bitsums and Operators
Reply With Quote #36

Quote:
Originally Posted by Emp` View Post
If I have
Code:
(1<<CSW_*)
Is there a way to get the CSW_* ?
PHP Code:
#define AddFlag(%1,%2)    ( %1 |= ( 1 << (%2-1) ) )
#define RemoveFlag(%1,%2) ( %1 &= ~( 1 << (%2-1) ) )
#define CheckFlag(%1,%2)  ( %1 & ( 1 << (%2-1) ) )

public Test()
{
    new 
iWeapList;
    new 
szWeap[41];

    
AddFlagiWeapList CSW_AWP );
    
AddFlagiWeapList CSW_DEAGLE );
    
AddFlagiWeapList CSW_SCOUT );
    
AddFlagiWeapList CSW_HEGRENADE );
    
    for ( new 
32 i++ )
    {
        if ( 
CheckFlagiWeapList ) )
        {
            
get_weaponnameszWeap 40 );
            
server_print("Found %s" szWeap );
        }
    }

__________________

Last edited by Bugsy; 04-21-2009 at 01:31.
Bugsy is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-20-2009 , 22:05   Re: [INFO] Bitsums and Operators
Reply With Quote #37

You should also add the '^' operator to this topic.
It switches the bit.

Code:
new bool:someBool[33]; public switchVar(client) {     someBool[client] = !someBool[client]; }

Code:
new someBitsum; public switchVar(client) {     someBitsum ^= (1 << (client - 1)); }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 04-20-2009 , 22:23   Re: [INFO] Bitsums and Operators
Reply With Quote #38

Quote:
Originally Posted by Exolent[jNr] View Post
You should also add the '^' operator to this topic.
It switches the bit.

Code:
new bool:someBool[33];

public switchVar(client) { someBool[client] = !someBool[client];
}



Code:
new someBitsum;

public switchVar(client) { someBitsum ^= (1 << (client - 1));
}

It can also check if a flag is present in one, and only one, of the compared bitsums. It's not used often, but it may be useful.

Code:
new iFlag1 = (1<<0)
new iFlag2 = (1<<0)

new iResult = iFlag1 ^ iFlag2 // = 0
__________________

Community / No support through PM
danielkza is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-20-2009 , 22:48   Re: [INFO] Bitsums and Operators
Reply With Quote #39

http://en.wikipedia.org/wiki/Bitwise_operation
__________________

Last edited by Bugsy; 04-21-2009 at 00:16.
Bugsy is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 04-21-2009 , 03:13   Re: [INFO] Bitsums and Operators
Reply With Quote #40

Stupid trivia. Why does this function:
PHP Code:
public some(id)
{
    static const 
indexes[] = {0,0x18,0x10,0x8};
    
    new 
value[]  = !"@@ "
    
    
new index
    
    
for(new i=3;i>=0;i--)
    {
        if(
value{i})
        {
            for(new 
j=0;j<=7;j++,index++)
            {            
                if(
value{i} & (<< j))
                {
                    
client_print(id,print_console,"Has (1 << %d)",index)
                }
            }
        }
        else
            
index indexes[i];
    }

Outputs:

Code:
Has (1 << 13)
Has (1 << 22)
Has (1 << 30)
?
__________________
joaquimandrade is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:08.


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