variables
-
How can I simplify this: grid[x][y] == 0 ? grid[x][y] = 1 : grid[x][y] = 0; I was thinking that I could make a pointer (or address) to that part of the array, then like shift the bits or something (each part of the array is a BYTE), but I couln't figure out how to do it. Any ideas? thanks
-
How can I simplify this: grid[x][y] == 0 ? grid[x][y] = 1 : grid[x][y] = 0; I was thinking that I could make a pointer (or address) to that part of the array, then like shift the bits or something (each part of the array is a BYTE), but I couln't figure out how to do it. Any ideas? thanks
-
grid[x][y] == 0 ? grid[x][y] = 1 : grid[x][y] = 0;
means basicly :if (grid[x][y] == 0) {
grid[x][y] = 1;
}
else {
grid[x][y] = 0;
}
TOXCCT >>> GEII power
[toxcct][VisualCalc]Oh, yeah, I wasn't talking simplifying like that, I meant something like BYTE GridPos = &grid[x][y];//might not even need this GridPos &= GridPos; (I know thats wrong, but thats what I'm thinking it should look like, just diffrent opperators)
-
Oh, yeah, I wasn't talking simplifying like that, I meant something like BYTE GridPos = &grid[x][y];//might not even need this GridPos &= GridPos; (I know thats wrong, but thats what I'm thinking it should look like, just diffrent opperators)
don't ... it looks ugly, it's unreadable ... I suggest keeping it as simple as possible and let the compiler do the work for you.
Maximilien Lincourt Your Head A Splode - Strong Bad
-
Oh, yeah, I wasn't talking simplifying like that, I meant something like BYTE GridPos = &grid[x][y];//might not even need this GridPos &= GridPos; (I know thats wrong, but thats what I'm thinking it should look like, just diffrent opperators)
ok, if we consider the test (
== 0
) MUST be performed befor doing anything on the matrix, the code is not very "simplifying". if not, i consider that, ifgrid[x][y]
equal 0, it must be set to 1, and if it equals 1, it must be set to 0. it is then easy to do that with thebitwise not **~=** operator
:grid[x][y] ~= grid[x][y];
according to the table :
~ 1 0
= 0 1
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
How can I simplify this: grid[x][y] == 0 ? grid[x][y] = 1 : grid[x][y] = 0; I was thinking that I could make a pointer (or address) to that part of the array, then like shift the bits or something (each part of the array is a BYTE), but I couln't figure out how to do it. Any ideas? thanks
I'm not sure what is non-simple about what you already have, but this is an alternative:
grid[x][y] = ! grid[x][y];
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
How can I simplify this: grid[x][y] == 0 ? grid[x][y] = 1 : grid[x][y] = 0; I was thinking that I could make a pointer (or address) to that part of the array, then like shift the bits or something (each part of the array is a BYTE), but I couln't figure out how to do it. Any ideas? thanks
Thanks all, I got it.