What do these operator do exactly

int m=5;

int n=4;

k= m&n;

or

K = m|n;

thx

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...

- 05-25-2002 #1UnregisteredGuest
## | and &

What do these operator do exactly

int m=5;

int n=4;

k= m&n;

or

K = m|n;

thx

- 05-25-2002 #2

- Join Date
- Aug 2001
- Location
- Groningen (NL)
- Posts
- 2,386

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.

- 05-25-2002 #3UnregisteredGuest
Thanx

But could you tell me that in lamance nubee terms

for m=5 and n=4

- 05-25-2002 #4

- Join Date
- Aug 2001
- Location
- Groningen (NL)
- Posts
- 2,386

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

m | n = 5

m & n = 4

There are some more bitwise operators, read this thread for more info:

http://www.cprogramming.com/cboard/s...wise+operatorsLast edited by Shiro; 05-25-2002 at 08:04 AM.

- 05-25-2002 #5UnregisteredGuest
Thanx really appreciated. Got a c exam 2morrow so just going through a few things

Thanx again shaun

- 05-25-2002 #6UnregisteredGuest
Sorry to bug you again but what if they where changed

from m||n

and m&&n

- 05-25-2002 #7

- Join Date
- Aug 2001
- Location
- Groningen (NL)
- Posts
- 2,386

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.

- Exactly how to get started with C++ (or C) today
- C Tutorial
- C++ Tutorial
- 5 ways you can learn to program faster
- The 5 Most Common Problems New Programmers Face
- How to set up a compiler
- 8 Common programming Mistakes
- What is C++11?
- Creating a game, from start to finish

- How to create a shared library on Linux with GCC - December 30, 2011
- Enum classes and nullptr in C++11 - November 27, 2011
- Learn about The Hash Table - November 20, 2011
- Rvalue References and Move Semantics in C++11 - November 13, 2011
- C and C++ for Java Programmers - November 5, 2011
- A Gentle Introduction to C++ IO Streams - October 10, 2011