# How to clear this offset bit?

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

## Recommended Posts

void Remove(const T* inValue)
{
int offset = inValue->x*MAXTILE_YLEN + inValue->z;
mbVisited[offset] &= ~(1 << inValue->direction);
Count--;
}

BYTE     mbVisited[MAXTILE_XLEN*MAXTILE_YLEN];

I want to clear the corresponding mbVisited bit based on the x,y and dir given as
the argument to Remove.
But I am not sure if this would work or not?
Thanks
Jack

Edited by lucky6969b

##### Share on other sites
Did you test it? We are not your Visual Studio debugger.

You did not give us enough information and it would have been faster just to try it in your debugger (since you have already written the code).
The array is based off X and Y but your offset is calculated via X and Z. Why?
Is direction the bit index into that byte? 0-7?

You’ve already written it, so why did you post it here instead of just testing it in a debugger? Why don’t you tell us if it works or not?

L. Spiro

##### Share on other sites

I need to check it. But for the time being, it is working as normal.

But I am not sure, because I copy it off somewhere from the web.

##### Share on other sites

You could verify the function by reading the documentation of the bitwise operators used therein, and testing it by feeding various values to it and comparing the returned values with known, expected values. It would also be a good chance to learn unit testing.

It is dangerous to use copy/pasted code in production projects, if you don't understand what it does. When stuff breaks, it is your fault, whether or not you understand why.

Edited by Nik02

##### Share on other sites

Unit tests are your friend. An important step when integrating 3rd-party code is to write unit/integration tests that ensure it does in fact work as you think it does.

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
17
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002295
×