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.


Example statement with a single "&":
  if (edgeTable[cubeindex] & 1)
      vertlist[0] =

Thank you in advance and God bless...

Last edited on
That's a bitwise and. Look here for more details about bitwise operations:
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
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. :)
Registered users can post here. Sign in or register to post.