Now I want to tackle the bitwise AND & syntax.
I think I am clear now on how we've come up with our 16 bit WORD seeds and what not.
For this example it is W0=%0000000011101101
When something like this is done:
<b>randomlight=W0 & $000F</b>
it is also like saying:
<b>randomlight=W0 & %1111</b> correct?
It is comparing the first four bits of the word so it looks like this:
<b>%0000000011101101</b> - original word
<b>%0000000000001111</b> - AND compare on bitlevel (narrow it down to 16 or less)
<b>%0000000000001101</b> - result of the compare
No matter how you compare with the second set of bits the results is the first four bits of the first set. The "&000F" is just a handy way of stripping away the bits that aren't needed?
My result comes back as a decimal 13 in this case.
But if I do it wanting to pick from 15 lights instead:
<b>%0000000011101101</b> - original word
<b>%0000000000001110</b> - AND compare on bitlevel (narrow it down to 15 or less)
<b>%0000000000001100</b> - result of the compare
Decimal 12
If I wanted to I could compare any number of bits by adjusting the second row of numbers so I could use & %00FF to come up with:
<b>%0000000011101101</b> - original word
<b>%0000000011111111</b> - AND compare on bitlevel (narrow it down to 255 or less)
<b>%0000000011101101</b> - result of the compare
Decimal 237
<b>%0001011011101001</b> - original word
<b>%0000000011111110</b> - AND compare on bitlevel (narrow it down to 254 or less)
<b>%0000000011101000</b> - result of the compare
Decimal 232
The only problem here is that I don't see where the results are <em>seldom</em> different in the final row than what the original first few bits in all the examples I also did on paper unless the second row has lots of zeros compared to the first row so I think I am missing a key point?
It is getting a little confusing now understanding the exact function of bitwise AND. Can someone expand to fill in the gaps here?
Am I, at least, close on this operation?
Thanks.
Bart
Bookmarks