Raised This Month: $12 Target: $400
 3% 

[TUT] Bits, Bit-fields, and Bit-wise Operators


Post New Thread Reply   
 
Thread Tools Display Modes
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 06-09-2017 , 15:55   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #81

Nice tut, thanks Bugsy!
CrazY. is offline
happy_2012
Senior Member
Join Date: Aug 2012
Old 08-25-2018 , 03:31   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #82

Quote:
Originally Posted by Bugsy View Post
PHP Code:
BitCountiVal )
{
    
iVal iVal - ((iVal >> 1) & 0x55555555);                    
    
iVal = (iVal 0x33333333) + ((iVal >> 2) & 0x33333333);     
    return ((
iVal + (iVal >> 4) & 0xF0F0F0F) * 0x1010101) >> 24

This page has a lot of interesting bit hacks.
Does this count players with multiple bitsums at the same time?

e.g. BitCount( bitsum_is_zombie | bitsum_is_alive )
happy_2012 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-25-2018 , 03:47   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #83

Quote:
Originally Posted by happy_2012 View Post
Does this count players with multiple bitsums at the same time?

e.g. BitCount( bitsum_is_zombie | bitsum_is_alive )
A bitsum can only be a single attribute for all players OR multiple attributes for one player, not both. Based on the description, it will return the number of bits that are set to 1 in that bitsum.
__________________
fysiks is offline
happy_2012
Senior Member
Join Date: Aug 2012
Old 08-25-2018 , 06:49   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #84

Is it not possible to do something similar to the stuff I mentioned though?

e.g. BitCount( bitsum_is_zombie | bitsum_is_alive )
happy_2012 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-25-2018 , 07:06   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #85

No, that counts players with either of those. Do & instead of | if you want players with both conditions met.
__________________
klippy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-25-2018 , 14:07   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #86

Quote:
Originally Posted by happy_2012 View Post
Is it not possible to do something similar to the stuff I mentioned though?

e.g. BitCount( bitsum_is_zombie | bitsum_is_alive )
Oh, I guess I misunderstood what you were asking. KliPPy is correct, if you want to check for players that have zombie OR alive, you use OR and if you want to check for players that have both zombie AND alive, you use AND.
__________________
fysiks is offline
happy_2012
Senior Member
Join Date: Aug 2012
Old 08-27-2018 , 01:55   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #87

Thank you very much

I am going to try it very soon ^^
happy_2012 is offline
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 09-15-2021 , 03:18   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #88

@Bugsy.
With the method of bit shifting in Enum.
How many items can we have in Enum ?
Abhinash is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-15-2021 , 03:51   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #89

Every "item" in an enum is 32 bits. At every step, you shift one bit to the left. Based on this information can you figure out how many items you can have?
__________________
HamletEagle is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-15-2021 , 06:07   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #90

Yes, the limiting factor is the number of bits in a 4-byte cell.

HamletEagle, I think it's better to say each enum item is 1 bit.
__________________

Last edited by Bugsy; 09-15-2021 at 06:46.
Bugsy is offline
Reply


Thread Tools
Display Modes

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 11:15.


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