Bitwise AND expanation

Started by
10 comments, last by Khatharr 11 years, 5 months ago

What if I make this:

if(63 & 1)
{
...
}


When will the if-loop start?
Is the condition everytime true, and is it possible to be false with an other number?


You are mistaken. an "if" is not a loop, because it only runs once. If you want to loop, you have to use the while loop, for loop, or do while; loop. If you put plain numbers in the if brackets, the result will always be the same, either always true or always false.

In the case of 63 & 1:
63[sub]10[/sub] = 00111111[sub]2[/sub]
1[sub]10[/sub] = 00000001[sub]2[/sub]

00111111
00000001 &
00000001

00000001[sub]2[/sub] = 1[sub]10[/sub]
so
if(63 & 1)
is equal to
if(1)

That means what comes after the if will always be executed.
Advertisement

(P and Q).


Upvoted for going full on geek mode.
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

This topic is closed to new replies.

Advertisement