   Hex Tile Map Problem Solving
  trying to plot some hexes (tiles/sprites) correctly, I'm following this article>>> http://www.gamedev.net/reference/articles/article1800.aspBut there is some psuedo code I cannot translate correctly in C#In the section described: Converting pixel coordinates to array coordinatesHe writes this code here, //pseudo Code!!!SectX := PixelX div (2 * TileR);SectY := PixelY div (HexagonH + HexagonS);SectPxlX := PixelX mod (2 * TileR);SectPxlY := PixelY mod (HexagonH + HexagonS);If (SectY AND 1 = 0) then SectTyp := A else SectTyp := B;The only part i am having trouble is this line >>If (SectY AND 1 = 0) then SectTyp := A else SectTyp := B;I am thinking that SectTyp is a boolean, so that is not a problemBut what does he mean by (SectY AND 1 = 0)in C# I would think this would look likeif (SectY & 1 == 0){    SectTyp = true;}else{    SectTyp = false;}but how does 1 = 0???   
  Using parentheses for clarity, I think the intended logic is:if ((SectY & 1) == 0)Which basically means that the even-numbered rows will be classified as type 'A', while the odd-numbered rows will be classified as type 'B'.   ;  Oooh thank you so much! That solves my compiling issue, could you help me understand additionally what & means?in my code SectY is mapSection.YmapSection is a Vector2i use floats for most everything but I can convert to int no problemlets say SectY = 5if ((5 & 1) == 0){ something}else{}what does 5 & 1 trying to do? I dont understand &I know what && is that is actually a AND, but I don't know &;  The technique being used here is bitmasking. I'm not going to go into a lot of detail here, but the general idea behind the bit of code you're asking about is this. If you look at the binary bit patterns for successive integers starting at 0, you get something like this (LSB on the right):0 = 00001 = 00012 = 00103 = 00114 = 01005 = 01016 = 01107 = 0111And so on.As you can see above, the bit pattern for '1' is 0001 (I'm just showing 4 bits here for clarity). In this context, '&' represents a bitwise logical AND operation. If you take the bitwise logical AND of 0001 and each of the numbers shown above, you'll get a value of 0 for even numbers and a value of 1 for odd numbers. This is a commonly used method for quickly determining if a number is even or odd (in this case, what we're trying to determine is whether the row of hexagons in question is an even row - type 'A' - or an odd row - type 'B').Disclaimer: The above explanation is informal and off the top of my head and may not stand up to rigorous examination, but the basic ideas being presented should be correct.   ;  Thanks!! That is very useful!howeverwould this work?if (SectY & == 0)why must a 1 be added to the arguementif (SectY & 1 == 0)   ;Quote:why must a 1 be added to the arguementif (SectY & 1 == 0)Well, that's explained in my post above. However, I'll go ahead and ask, what would this:if (SectY & == 0)Mean exactly? What would this statement do?   ;  oh I get & is comparing one thing to something elsebut if 1 = 0001 which = oddthen wuold this work?if (SectY & 1){    odd}else{    even}   ;  That will work in languages in which integer values can be implicitly converted to Boolean values (with 0 evaluating to false and all other values evaluating to true).   ;  ahhh - thankyou so much for the insight. This has been very helpful - I've been able to plot my hex map perfectly now. Now im going to work on the selectable hex tiles via mouse coordinates.   ;  I used a different method for selection than the one presented in the article.It "offsets" the selection just like in rendering, so you will have only one type of selection:And I found that in case of small hexes, this rectangular approximation is just enough.If you want precise selection, you can perform 4 additional checks in the colored corners. You can make the equations of the lines, then check if 'y' is greater or less, if x is put in the equation.   