Unbelievable video!
I think visual studio is malfunctioning, Im doing an if (0&1==0) and its firing the else line! but in the debug watch 1&0 is calculating to 0.
Here I need a video for more evidence→
This makes no sense!
Unbelievable video!
I think visual studio is malfunctioning, Im doing an if (0&1==0) and its firing the else line! but in the debug watch 1&0 is calculating to 0.
Here I need a video for more evidence→
This makes no sense!
Hello friend. Remain calm….this is going to sting a little.
The single ‘&’ is a bit-wise operator when used this way.
The double ‘&&’ is the boolean “and” operator.
((0&1) == 0) is saying that ‘0’ is an even number because the bit in the one position is zero.
((1&1) == 1) is true because in base two 1 is 0x0001 and there is a bit set in the one position
((2&1) == 0) is good meaning there is not a bit set in the one position. 0x0010 which is two.
((3&1) == 1) is true. 3 is an odd number. 3 in base2 is 0x0011
There is a ton of power in the bit-wise & operator when usage advances past the last bit.
Dev careful. Pixel on board.
Buckle up. Everything will be revealed.
(0&1 == 0) is saying that ‘0’ is an even number because the bit in the one position is zero.
Yeh, but it isnt responding as 0! its firing the else line, the if(0&1==0) ISNT coming true when it should be!
Then it may be an operator precedence issue.
Rewrite as
if((0&1) == 0)
Dev careful. Pixel on board.
Buckle up. Everything will be revealed.
YOU WERE RIGHT! THANKS!!!!
gamedev rules.
Ill remember that. “dont forget to bracket ur bitwise ands!!!” because the comparison operator takes prescedence over them.
Which is complete garbage really, why the hell did they code it like that?
I'm surprised the compiler didn't produce a warning.
Dev careful. Pixel on board.
Buckle up. Everything will be revealed.
MitsubishiMagna said:
I think visual studio is malfunctioning, Im doing an if (0&1==0) and its firing the else line!
At this basic level, tooling is always correct. There are a zillion people doing bitwise operations every single day, so if the software would really be broken, others would find it too and report and/or publish about it.
In other words, in these cases you can just assume there is something wrong with your understanding what you wrote.
The second thing here is that unless you are doing something extremely weird or new, other people have been in your situation before, and wrote questions about it on the internet. Other people have responded to that, so for every non-extreme/new problem, you can safely assume the internet has an answer to your problem. Searching for the same problem will pretty much instantly point you to the relevant discussions, and if you read that, you will find out what is wrong with your understanding much much quicker than by posting about it.
In addition, in my experience, in good discussions you often find pointers to related or different solutions that you haven't even considered yourself, and in quite some cases those alternatives are even better. So you may at the same time learn more about programming, which cannot be a bad thing 🙂