Raised This Month: $32 Target: $400
 8% 

[INFO] Bitsums and Operators


Post New Thread Reply   
 
Thread Tools Display Modes
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-24-2009 , 10:09   Re: [INFO] Bitsums and Operators
Reply With Quote #61

I also confirm that it works. (And also, thanks Damizean)

The improvement:
PHP Code:
dateSun May 24 06:58:56 2009 mapde_dust2
type 
|                             name |      calls time min max
-------------------------------------------------------------------
   
|                       server_cmd |          0.000014 0.000014 0.000014
   p 
|                       plugin_cfg |          0.041587 0.041587 0.041587
   f 
|                           oldWay |      10000 0.025170 0.000001 0.000081
   f 
|                           newWay |      10000 0.024912 0.000001 0.000103
0 natives
public callbacksfunction calls were not executed
Attached Files
File Type: sma Get Plugin or Get Source (bits.sma - 607 views - 279 Bytes)
__________________

Last edited by joaquimandrade; 05-24-2009 at 11:18.
joaquimandrade is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-24-2009 , 12:56   Re: [INFO] Bitsums and Operators
Reply With Quote #62

I understand the "x / 32" -> "x >> 5" because like you said, bitshifting is a power of 2.
x * power(2, y) = x << y
x / power(2, y) = x >> y

However, I don't understand why "x % 32" was changed to "x & 31".
I know that the & operator compares the bits, but it just doesn't make sense to me.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-24-2009 , 13:19   Re: [INFO] Bitsums and Operators
Reply With Quote #63

Quote:
Originally Posted by Exolent[jNr] View Post
I understand the "x / 32" -> "x >> 5" because like you said, bitshifting is a power of 2.
x * power(2, y) = x << y
x / power(2, y) = x >> y

However, I don't understand why "x % 32" was changed to "x & 31".
I know that the & operator compares the bits, but it just doesn't make sense to me.
x & 31 will translate always to a value between 0 and 31. That's part is obvious (And that's what we want). Then, the less obvious, is how the result value "cycles":

When x is a power of 2 bigger or equal to 32 (i.e. 32,64,128,...) , (x & 31) is 0

Code:
(32)
  0000011111
& 0000100000

(64)
  0000011111
& 0001000000

(128)
  0000011111
& 0010000000
When x grows after that, (x & 31) will grow equally until be again a power of 2.

Code:
(33) => (33 & 31) == 1
  0000011111
& 0000100001

(34) => (34 & 31) == 2
  0000011111
& 0000100010

(35) => (35 & 31) == 3
  0000011111
& 0000100011

...

(63) => (63 & 31) == 31
  0000011111
& 0000111111

(64) => (64 & 31) == 0
  0000011111
& 0001000000
So, basically it goes:

0 .. 31 , 0 ... 31
__________________
joaquimandrade is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-24-2009 , 13:41   Re: [INFO] Bitsums and Operators
Reply With Quote #64

I pretty much understand it now, thanks.
I guess I need to brush up on my knowledge of bits.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-24-2009 , 13:43   Re: [INFO] Bitsums and Operators
Reply With Quote #65

Quote:
Originally Posted by Exolent[jNr] View Post
I pretty much understand it now, thanks.
I guess I need to brush up on my knowledge of bits.
I guess that this is pretty much advanced stuff. Probably this guy has some special knowledge on this topic
__________________
joaquimandrade is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-24-2009 , 14:31   Re: [INFO] Bitsums and Operators
Reply With Quote #66

Here's a few examples of what is taking place:

Code:
34 & 31 = 2 === 34 % 32 = 2

The only matching bit (&) out of these two numbers is bit 2 which represents 2.
34 = 100010
31 = 011111
02 = 000010  =  Result of 34 & 31

34 modulus 32 = 2
Code:
19 & 31 = 19 === 19 % 32 = 19

The bits that match up in these two numbers represents 19.
19 = 10011
31 = 11111
19 = 10011  =  Result of 19 & 31

19 modulus 32 = 19
Code:
32 & 31 = 0 === 32 % 32 = 0

Notice that no bits match so the result of this is 0
32 = 100000
31 = 011111
00 = 000000  == Result of 32 & 31 

32 modulus 32 = 0
Here's a little web tool you can use to play with binary <-> decimal.
http://www.openstrike.co.uk/cgi-bin/decimalbinary.cgi

Here's a printout of the values for 0 - 34 comparing ( x & 31 ) and ( x % 32 )
Code:
0 & 31 = 0 === 0 % 32 = 0
1 & 31 = 1 === 1 % 32 = 1
2 & 31 = 2 === 2 % 32 = 2
3 & 31 = 3 === 3 % 32 = 3
4 & 31 = 4 === 4 % 32 = 4
5 & 31 = 5 === 5 % 32 = 5
6 & 31 = 6 === 6 % 32 = 6
7 & 31 = 7 === 7 % 32 = 7
8 & 31 = 8 === 8 % 32 = 8
9 & 31 = 9 === 9 % 32 = 9
10 & 31 = 10 === 10 % 32 = 10
11 & 31 = 11 === 11 % 32 = 11
12 & 31 = 12 === 12 % 32 = 12
13 & 31 = 13 === 13 % 32 = 13
14 & 31 = 14 === 14 % 32 = 14
15 & 31 = 15 === 15 % 32 = 15
16 & 31 = 16 === 16 % 32 = 16
17 & 31 = 17 === 17 % 32 = 17
18 & 31 = 18 === 18 % 32 = 18
19 & 31 = 19 === 19 % 32 = 19
20 & 31 = 20 === 20 % 32 = 20
21 & 31 = 21 === 21 % 32 = 21
22 & 31 = 22 === 22 % 32 = 22
23 & 31 = 23 === 23 % 32 = 23
24 & 31 = 24 === 24 % 32 = 24
25 & 31 = 25 === 25 % 32 = 25
26 & 31 = 26 === 26 % 32 = 26
27 & 31 = 27 === 27 % 32 = 27
28 & 31 = 28 === 28 % 32 = 28
29 & 31 = 29 === 29 % 32 = 29
30 & 31 = 30 === 30 % 32 = 30
31 & 31 = 31 === 31 % 32 = 31
32 & 31 = 0 === 32 % 32 = 0
33 & 31 = 1 === 33 % 32 = 1
34 & 31 = 2 === 34 % 32 = 2
__________________

Last edited by Bugsy; 05-24-2009 at 14:45.
Bugsy is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-24-2009 , 14:38   Re: [INFO] Bitsums and Operators
Reply With Quote #67

Okay, I understand it now.
I was looking at it in a totally wrong way.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 05-24-2009 , 16:06   Re: [INFO] Bitsums and Operators
Reply With Quote #68

It didn't get through my thick skull until I saw this:

Quote:
Originally Posted by Bugsy View Post
Code:
34 & 31 = 2 === 34 % 32 = 2

The only matching bit (&) out of these two numbers is bit 2 which represents 2.
34 = 100010
31 = 011111
02 = 000010  =  Result of 34 & 31

34 modulus 32 = 2
Thanks for taking the time to explain this stuff, guys
__________________
stupok is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 07-09-2009 , 02:58   Re: [INFO] Bitsums and Operators
Reply With Quote #69

I recommend a good article about bits
http://www-graphics.stanford.edu/~seander/bithacks.html
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 10-26-2013 , 16:20   Re: [INFO] Bitsums and Operators
Reply With Quote #70

Are you sure the next expressions are true, ot_207?

PHP Code:
~0
~
__________________

Last edited by claudiuhks; 10-26-2013 at 16:21.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Reply



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 19:10.


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