How do you perform the binary operation '&' on
two ints? and what does it do?
I thought '&' was '&&' and used for logical operations...
Any help is appreciated
This is a discussion on & operator within the C Programming forums, part of the General Programming Boards category; How do you perform the binary operation '&' on two ints? and what does it do? I thought '&' was ...
How do you perform the binary operation '&' on
two ints? and what does it do?
I thought '&' was '&&' and used for logical operations...
Any help is appreciated
> what does it do?
All numbers are represented in binary, right?
So, let's say i == 4 and j == 6.
4 == 100 in binary
6 == 110 in binary
4 & 6 == 100 == 4
Whichever bits the two values both have set will be set in the answer
-Govtcheez
govtcheez03@hotmail.com
The &-operator is the bitwise logical AND.
Assume A and B are integers, than C, which is (A AND B) can be calculated as follows:
C = A & B
The result depends on the values of A and B. Bitwise:
1 & 1 = 1
1 & 0 = 0
0 & 1 = 0
0 & 0 = 0
Example of bitwise AND for a:
A = 1111 0101
B = 0100 1001
--------------------
C = 0100 0001
&& is a logical operation which can be used in for example if-constructions. Assume E and F are expressions. Then
If and only if E evaluates to TRUE and F evaluates to TRUE, then the code between the brackets will be executed.Code:if (E == TRUE && F == TRUE) { }