Hello all-

I'm trying to create a recursive function used for 3D maze traversal. The data for each maze section is stored in a byte. Each bit in the byte, with the exception of the MSB and the 2nd MSB, represents a place where a wall would be. In order to make sure that there are no illegal moves, I need to do error checking using bitwise operations. Let me give an example of what each section of the error checking looks like. After checking, via if and else if respectively, if all three dimension values are 0, or if I've already passed over a space (represented by the MSB), I pull up the else statement:

Code:
else{
        if (0x1 == 3dmaze[i][j][k] & 0x1)
            return 0;
        else{ if (!function(3dmaze,i-1,j,k)){
//...
                } printf("%i %i %i\n", i, j, k); printf("e");maze[i][j][k] = (maze[i][j][k] | 0x80); return 1;
        } 
    }
//The if/else statements continue for each bit going R to L.
//Hex values and i/j/k modifications are also adjusted accordingly.
This section is specifically where my problem is. The starting coordinate is (1,2,1). For some reason, the program sees this, pulls up the else statement, calculates the new coordinates as (0,2,1), does the process again, and then calculates the new coordinates as (-1,2,1). Naturally this means that the program will crash.

I've tried a debug measure by printing out the hex values in each section, and for some reason they don't make sense.
(ex. the contents of (1,2,1) is 0xffffffdb)
I can see if the values won't compare for that reason, but I know for a fact that the read-in file is not corrupted.

How could I make it so that my program isn't going to keep on making this error?

(I'm working on this issue as I post; if I find a solution before anyone else, I'll be sure to update.)