#### Archived

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

# '& 0x0000001F'!???

This topic is 6043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 on other sites
Thanks Null and Void, I also just now found "Bitwise Operations in C" written by him
http://www.gamedev.net/reference/programming/features/bitwise/

Edited by - mrSpidey007 on November 6, 2001 9:01:28 PM

• 12
• 40
• 15
• 10
• 23