Single "&" Inside The If-Statement in C++?

Hello Professionals:

Good day. I am currently trying to understand a code from this website, but I don't why there is only one "&" in the IF-statement. Can anyone shed some light what it means? Thank you.

Link: http://paulbourke.net/geometry/polygonise/

Example statement with a single "&":
1
2
3
  if (edgeTable[cubeindex] & 1)
      vertlist[0] =
         VertexInterp(isolevel,grid.p[0],grid.p[1],grid.val[0],grid.val[1]);


Thank you in advance and God bless...



Last edited on
That's a bitwise and. Look here for more details about bitwise operations:
http://www.cplusplus.com/doc/boolean/
Last edited on
Thanks @Golden Lizard for the response. I was just wondering why they used "bitwise and"? What is the purpose? And what will the effect in using this?
It' a bitwise AND.
In this case, it tests if the bit 0* is set is the value edgeTable[cubeindex].
*: pow(2, 0) = 1
See http://en.cppreference.com/w/cpp/language/operator_arithmetic
some (older? C?) code uses a character or integer as a 'set' of 8, 16, 32 etc boolean values. You just set and check the bit you want. It is not uncommon to have such a thing in a header for a serial stream (think: ethernet message packet) to identify which items from a set of possible items are in the packet rather than burn a full byte for each one.
Last edited on
Thank you @Golden Lizard @fcantoro and @jonnin for your insights. God bless you all. :)
Topic archived. No new replies allowed.