Working with bits

Hello everyone, this is my first post here. I am currently working to improve the speed of an algorithm. This is just for fun, and I am not concerned with useability. I am just trying to get pure speed.

Currently I am using an array of 64 ints to denote a board. The ints will be 1 if the space is un visited and a 1 if the space has been visited. I would like to remove the iteration required to check if the board is "complete". Currently, I loop through the board looking for a 1. Is there a way I can establish a single variable as just bits:

1)The value of the variable would start as 111111111111111 (64 times)
2)To change the value of a single space, I would start at the memory address, shift n number of spaces and change the value. For example, to change the 4th space, I would shift and result in 111101111111...
3)To check for complete, I just see if the variable is 0. Any single 1 in the number will result in a false.

I am sure this is doable, I am just not sure how (or even if it is efficient)

std::uint64_t board(-1);

board &= ~(1 << 4);
This will set position 4 to 0. Not sure if that is what you meant.

if (board == 0)
	std::cout << "The board is complete!" << std::endl;
Last edited on
Awesome! I will test this this afternoon.

Thank you for such a quick and precise response.
I do have a follow up question. How do I test for equality of a particular space? For instance, if I wanted to see if space 4 was a 0 or 1.

Thank you.
Topic archived. No new replies allowed.