Original Post
Could someone expain me the bitwise and operation (&) in C++?
For example:
What happens here?
For example:
What happens here?
if(63 & 1)
{
......
}
if(63 & 1)
{
......
}
A bitwise AND takes two binary representations of equal length and performs the logical AND operation on each pair of corresponding bits. The result in each position is 1 if the first bit is 1 and the second bit is 1; otherwise, the result is 0. In this, we perform the multiplication of two bits; i.e., 1 × 0 = 0 and 1 × 1 = 1[/quote]
For instance, you have a = 100 (01100100) and b = 50 (00110010), and if you write c = a & b (100 & 50 == 32) the result is:
01100100 (100)
00110010 (50)
------------
00100000 (32)
Since the 6th column (from the right) is the only one with a 1 in both a and b.
EDIT: Way too slow, it seems :-)
int Zahl = (54 & 63);
std::cout << Zahl;
Yes, but I made a small programm wich results in:
int Zahl = (54 & 63);
std::cout << Zahl;
63= 111111
54= 110110
so Zahl = 54
What is the sense behind that?
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?
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?
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?
if(63 & 1)if(1)
(P and Q).
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more