Bit - include file (formally Boolean)
5 Attachment(s)
Hi, everyone!
I was using some bit manipulating stocks far more often, then to copy paste them everywhere all the time. I got a handful, and put it into an include file. Hope this set of stocks/functions - gonna add more if get new ones - will help everyone, who needs bit manipulation. The macros/stocks: PHP Code:
|
Re: Boolean - include file
There is already an xor operator.
Code:
I suggest id_to_flag() to limit to 31 instead of just subtracting 1. Code:
You could also do the same with your num_to_binstr() and also get rid of the conditional. Code:
|
Re: Boolean - include file
Updated it with your ideas, thank you very much. I left the limit to 32. A 31 sized bit array would be useless for 32 players on a server - I use these functions for player bits to avoid the following code types:
PHP Code:
|
Re: Boolean - include file
I don't see how your include has anything to do with booleans. Also, Bugsy has several common bit operations listed in his bitwise operations thread.
|
Re: Boolean - include file
I think those stocks names are quite confusing.
|
Re: Boolean - include file
Quote:
1<<(32-1) would give the same results as 1<<(32&1) but IIRC bit operations are quicker. |
Re: Boolean - include file
Quote:
|
Re: Boolean - include file
Quote:
|
Re: Boolean - include file
Quote:
Quote:
|
Re: Boolean - include file
Uploaded newer version, edited the stock names, added a new stock.
What you are arguing about are CPU cycles. But as I said, I only want to stop people using 32 bit bool-s to store 1 bit. Bool-s are usually used for switches, mostly for every player. With these type of bit manipulations, this problem is solved. Every player's switch can be stored in 1 integer. |
All times are GMT -4. The time now is 19:54. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.