Re: [INFO] Bitsums and Operators
1 Attachment(s)
I also confirm that it works. (And also, thanks Damizean)
The improvement: PHP Code:
|
Re: [INFO] Bitsums and Operators
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. |
Re: [INFO] Bitsums and Operators
Quote:
When x is a power of 2 bigger or equal to 32 (i.e. 32,64,128,...) , (x & 31) is 0 Code:
(32) Code:
(33) => (33 & 31) == 1 0 .. 31 , 0 ... 31 |
Re: [INFO] Bitsums and Operators
I pretty much understand it now, thanks.
I guess I need to brush up on my knowledge of bits. |
Re: [INFO] Bitsums and Operators
Quote:
|
Re: [INFO] Bitsums and Operators
Here's a few examples of what is taking place:
Code:
34 & 31 = 2 === 34 % 32 = 2 Code:
19 & 31 = 19 === 19 % 32 = 19 Code:
32 & 31 = 0 === 32 % 32 = 0 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 |
Re: [INFO] Bitsums and Operators
Okay, I understand it now.
I was looking at it in a totally wrong way. |
Re: [INFO] Bitsums and Operators
It didn't get through my thick skull until I saw this:
Quote:
|
Re: [INFO] Bitsums and Operators
I recommend a good article about bits
http://www-graphics.stanford.edu/~seander/bithacks.html |
Re: [INFO] Bitsums and Operators
Are you sure the next expressions are true, ot_207?
PHP Code:
|
All times are GMT -4. The time now is 14:36. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.