Raised This Month: $319 Target: $400
 79%   Almost there!

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


Post New Thread Reply   
 
Thread Tools Display Modes
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 09-16-2021 , 00:18   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #91

Quote:
Originally Posted by Bugsy View Post
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.
So, how many items can I have then 50, 100, 200 ?
Abhinash is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-16-2021 , 00:23   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #92

Google how many bits are in a byte, then multiply that value by 4.

You can do extra coding to extend beyond this 'enum limit' if needed.
__________________

Last edited by Bugsy; 09-16-2021 at 00:25.
Bugsy is offline
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 09-16-2021 , 03:00   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #93

Quote:
Originally Posted by Bugsy View Post
Google how many bits are in a byte, then multiply that value by 4.

You can do extra coding to extend beyond this 'enum limit' if needed.
So the result is 32 assuming cell as an signed 4 byte integer.
As in C++ also the max we can go is 32 items.

And how do you plan to exceed that 32 limit ?
Can you please show ?
Abhinash is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-16-2021 , 08:59   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #94

It's been covered before somewhere on the forums, but you'd need to create a macro or function to do this. Basically you'd use an array to get bits in excess of 32. So if you need 64 bits, you have an array bitField[ 2 ]. For bits 1-32 the first cell is used, for bits 33 to 64, the second cell is used, etc.
__________________
Bugsy is offline
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 09-16-2021 , 09:02   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #95

Quote:
Originally Posted by Bugsy View Post
It's been covered before somewhere on the forums, but you'd need to create a macro or function to do this. Basically you'd use an array to get bits in excess of 32. So if you need 64 bits, you have an array bitField[ 2 ]. For bits 1-32 the first cell is used, for bits 33 to 64, the second cell is used, etc.
Any link or the way to do it would be usefull ...
Abhinash is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-16-2021 , 09:13   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #96

Look here , post 49 and forward
https://forums.alliedmods.net/showth...t=90507&page=2
__________________

Last edited by Bugsy; 09-16-2021 at 09:13.
Bugsy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-16-2021 , 09:33   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #97

Out of curiosity, what are you trying to do that requires you to have more than 32 flags?
__________________
HamletEagle is offline
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 09-16-2021 , 20:56   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #98

Quote:
Originally Posted by HamletEagle View Post
Out of curiosity, what are you trying to do that requires you to have more than 32 flags?
Out of curiosity I just created a mod which currently has 32 different round types. Maybe in future I will add more. That's why I asked and also for knowledge. Because I am also learning C and C++.
Abhinash is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-16-2021 , 21:26   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #99

Quote:
Originally Posted by Abhinash View Post
Out of curiosity I just created a mod which currently has 32 different round types. Maybe in future I will add more. That's why I asked and also for knowledge. Because I am also learning C and C++.
"round type" sounds like something that has mutually exclusive values (i.e. two or more round types cannot be active at the same time). If this is true, then you shouldn't be using bits for storing these values, you should use an integer-based enum.
__________________
fysiks is offline
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 09-19-2021 , 10:58   Re: [TUT] Bits, Bit-fields, and Bit-wise Operators
Reply With Quote #100

Quote:
Originally Posted by fysiks View Post
"round type" sounds like something that has mutually exclusive values (i.e. two or more round types cannot be active at the same time). If this is true, then you shouldn't be using bits for storing these values, you should use an integer-based enum.
Ofcourse not. Both of them are not active at the same time. Only one at a time. And that is also reset at the round end to g_roundtype = R_NONE where value of R_NONE in the left bit shifting enum is '0'.
Abhinash 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:28.


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