Re: [INFO] Bitsums and Operators
Quote:
1 = 0000 0000 0000 0000 0000 0000 0000 0001 Doing a left shift of 32 will push the bit out of the bitfield: 1 << 32 = 1 0000 0000 0000 0000 0000 0000 0000 0000 You can make it work to hold player indexes (1-32) by subtracting 1 from the left-shift value so you will always shift 1 less (0-31 instead of 1-32). I used bit-fields in my Admin Hierarchy plugin instead of using arrays of 33 cells. The bit-field method is also nice because you can quickly check if any admins or bots are on the server with a simple !g_Bot or !g_Admin. I cannot get the profiler to work so I'm not sure which way is ultimately better. The bit-field is better to conserve memory as you are using 1 cell (4 bytes) vs. a 33 cell array (132 bytes) as a storage mechanism for player indexes. On the other hand, the array method may be less CPU expensive but it will obviously utilize more memory. PHP Code:
|
Re: [INFO] Bitsums and Operators
well its completly nonsence to me, i would never do all that crap in my codes... But thanks for info ;)
|
Re: [INFO] Bitsums and Operators
Quote:
Bugsy you can also do this: (i don't know how to put a % in a macro) 1 << value % 32 |
Re: [INFO] Bitsums and Operators
Quote:
PHP Code:
|
Re: [INFO] Bitsums and Operators
Nice Tutorial :D
I Will test this method :D |
Re: [INFO] Bitsums and Operators
While I do use bitwise operation I will never take it to the degree that you are proposing. I'd rather prefer legibility over whatever minimal degree of memory this would save (which is probably negligible anyway).
And while I do appreciate the write up, I think it's a bit complex for beginners or casual scripters to understand. |
Re: [INFO] Bitsums and Operators
Quote:
Quote:
|
Re: [INFO] Bitsums and Operators
I want to see a profile done on the correctly written bit-field code since the one done by Empowers is incorrect and may be skewing the results (1 << 32); I really want to see any performance difference in array vs. bit operators. The tut has to also be corrected so people don't attempt to use ( 1 << id ) for storing player id's; perhaps add my AddFlag, RemoveFlag, and CheckFlag macros too. :)
|
Re: [INFO] Bitsums and Operators
Quote:
|
Re: [INFO] Bitsums and Operators
Quote:
And I can't undersatand what u a saying about countinue. It let the loop run just makes i++. and break stops the loop. PHP Code:
+k :) but is this better? PHP Code:
And I have a question.. For example a have bitsum var.. 1230 and 4000 bit A true.. So should I loop thougth all to find them?? Or maybe there is better way |
All times are GMT -4. The time now is 22:03. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.