Hello..
So, in university they never mentioned the bitwise operators and the work with them. And now I've realised their power in the game development and I want to use them properly, and I'm doing fine, but I can't understand something..
If I'm comparing two integer numbers like this:
int num = 8;
if(num & 8){
// if number is equal to 8 it will show true
}
else{
// if not, it will show false
}
This seems to work fine, but once I try this:
int num = -8;
if(num & 8){
// it acts as the previous example..
}
else{
...
}
It executes the true block..
I guess this means that it thinks -8 and 8 are the same, because it's not really recorded as -8? (I'm not so sure if i'm right..)
I know that I need to convert the bits of the integer, and then add a '1' to the last bit to convert a integer to negative.
But how is this going to happen in C or C++?
Is there any function that does this for me?
Sorry for the low English..