# | and &

This is a discussion on | and & within the C Programming forums, part of the General Programming Boards category; What do these operator do exactly int m=5; int n=4; k= m&n; or K = m|n; thx...

1. ## | and &

What do these operator do exactly

int m=5;
int n=4;

k= m&n;

or

K = m|n;
thx

2. Those are bitwise binary operators.

The operator | is the logical or. Definition: x or y is 1 iff one of them or both are 1.

The operator & is the logical and. Definition: x and y is 1 iff both are 1.

3. Thanx

But could you tell me that in lamance nubee terms

for m=5 and n=4

4. In binary:

m = 0101
n = 0100

Apply &- and |-operation using the definition:

Code:
```m n m|n
0 0  0
1 1  1
0 0  0
1 0  1

m n m&n
0 0  0
1 1  1
0 0  0
1 0  0```
So in decimal:

m | n = 5
m & n = 4

http://www.cprogramming.com/cboard/s...wise+operators

5. Thanx really appreciated. Got a c exam 2morrow so just going through a few things

Thanx again shaun

6. Sorry to bug you again but what if they where changed

from m||n

and m&&n

7. The operators || and && are relational operators and no binary operators.

(A || B) is 1 if (A > 0) or (B > 0), else 0.
(A && B) is 1 if (A > 0) and (B > 0), else 0.

Note that A and B are not necessarily bits, they can also be of type int, char etc.