Archived

This topic is now archived and is closed to further replies.

MrSpidey007

'& 0x0000001F'!???

Recommended Posts

in the Game Programming Genesis tutorial http://www.gamedev.net/reference/articles/article1304.asp to calculate if a number is he uses someting like: int x = themap->xCamera & 0x0000001F; to caluclate if themap->xCamera is divisible by 32. This is the only part of his code that I don''t understand how it works. I want to create a tile engine with 16 pixel tiles. How does this work? what does the ''&'' do and how can I change it to calculate if a number is divisible by 16? Thanks

Share this post


Link to post
Share on other sites
Ewww...magic numbers

"I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours." - - Stephen Roberts

Share this post


Link to post
Share on other sites
The ''and'' trick to test for divisibility only works with base 2 numbers. He took 32, subtracted one, and converted it to hexidecimal (not required, but it is good style for when you''re doing bitwise operations). Replace the 0x0000001F with 0x0F to test if it is divisible by 16.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites