Rules FAQ Members List Search Register Login

 Raised This Month: \$158 Target: \$400 39%

Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
 05-20-2014 , 11:57   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators #71 claudiuhks: That post is over three years old. __________________ Last edited by Bugsy; 05-20-2014 at 11:59.
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
 05-13-2015 , 20:16   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators #72 Stock that returns the number of SetBits in a bitfield, aka hamming weight or popcount: PHP Code: ```      NumberOfSetBits(iBitField)    {        iBitField = iBitField - ((iBitField >> 1) & 0x55555555);        iBitField = (iBitField & 0x33333333) + ((iBitField >> 2) & 0x33333333);        return (((iBitField + (iBitField >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;    }  ``` Taken from here
PartialCloning
Senior Member
Join Date: Dec 2015
 08-30-2016 , 03:00   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators #73 If I have a variable equal to (1 << value) is it possible to get the value part of it?
KliPPy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
 08-30-2016 , 07:03   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators #74 I can't think of any efficient way, but what exactly are you trying to achieve? Having to find that value doesn't seem like a good thing to me. EDIT: This could work, but I don't like that it's a loop: PHP Code: ``` getValue(variable) {    for(new i = 0; i < 32; i++) {        if(variable == (1 << i)) {            return i;        }    }        // Some invalid state I guess, variable has more than 1 bit set.    return -1;}  ``` Last edited by KliPPy; 08-30-2016 at 07:07.
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
 08-30-2016 , 20:52   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators #75 Alternative to KliPPy's: PHP Code: ``` stock BitShiftCount( x ){    new i;    while ( x && !( x & 1 ) )    {        x >>= 1;        i++;    }    return i;}  ``` Last edited by Emp`; 08-31-2016 at 19:07. Reason: forgot this isn't the SourceMod section
 08-30-2016, 23:31 Bugsy This message has been deleted by Bugsy. Reason: nvm, misread
Bos93
Veteran Member
Join Date: Jul 2010
 08-31-2016 , 18:53   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators #76 int i __________________
Depresie
Veteran Member
Join Date: Nov 2013
 10-02-2016 , 22:35   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators #77 Now this, this is, this is a fucking bad ass tutorial, these little fuckers can be extremely useful I tried to learn about bits some time ago, but i couldn't understand even the basic things from what i found on google, but this man is golden when it comes to tutorials Thanks Bugs __________________
eyal282
Veteran Member
Join Date: Aug 2011
 06-06-2017 , 10:43   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators #78 Can you do for example: #define SetUserBool(%1,%2) ( %1 |= (1 << (%2 - 1))) Because it will range from 0 to 31. Last edited by eyal282; 06-06-2017 at 18:08.
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
 06-06-2017 , 10:52   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators #79 SetUserBool(%1,%2) ( %1 |= (1 << (%2 - 1))) You used |= instead of left shift and you should shift 1, not %1, but yea that will work as long as only 1 to 32 are inputted. Same logic as using ( %2 & 31 ). __________________ Last edited by Bugsy; 06-06-2017 at 10:53.
eyal282
Veteran Member
Join Date: Aug 2011
06-06-2017 , 18:07   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
#80

Quote:
 Originally Posted by Bugsy SetUserBool(%1,%2) ( %1 |= (1 << (%2 - 1))) You used |= instead of left shift and you should shift 1, not %1, but yea that will work as long as only 1 to 32 are inputted. Same logic as using ( %2 & 31 ).
Yeah, mistake.

 Thread Tools Display Modes Linear Mode

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Server Discussion     Source Servers (SRCDS)     HL1 Servers (HLDS) AMX Mod X     News     Bug Reports     General     Off-Topic     Plugins         Suggestions / Requests         Approved Plugins         New Plugin Submissions         Unapproved/Old Plugins         Translation Request         High-Traffic Plugins             GunGame             UAIO (Ultimate All-In-One Plugin)             xREDIRECT             CSDM             AMX Super             RuneMod             Zombie Plague Mod             SuperHero Mod                 News                 Tech Support                 Scripting Help                 Off-Topic / General Chat                 Heroes                     Suggestions / Requests                     Approved Heroes                     New Submissions                     Unapproved/Old Heroes                         Module Heroes                     SuperHero Mod Stats - By 123                 (OLD) Bug Reports     Scripting         Scripting Help         Code Snippets/Tutorials         Module Coding     Donor Access SourceMod     News     General     Plugins         Plugins         Unapproved Plugins         Plugin/Gameplay Ideas and Requests         High-Traffic Plugins             SourceMod Anti-Cheat             Zombie:Reloaded             SourceBans / SourceBans++             VSH / Freak Fortress             Store             SM_Hosties             HLstatsX:CE     Scripting     Extensions     Snippets and Tutorials     Donor Access     Metamod: Source         Metamod:Source Plugins         Metamod:Source Questions         Coding MM:S Plugins & SM Extensions Hosted Stuff     Asherkin's Plugins         TF2Items         TFDodgeball         SteamTools     Bail's Plugins         CSDM         CS:S DM Off-Topic & Trash     Off-Topic     Trash

All times are GMT -4. The time now is 23:32.

 DMCA - Archive - Top