Binary Operator in C++
Here are the implementation of Binary Operator in C++ language:
#include <iostream>
using namespace std;
int main()
{
int a = 10;
int b = 5;
// Binary addition (+)
cout << "a + b = " << a + b << endl;
// Binary subtraction (-)
cout << "a - b = " << a - b << endl;
// Binary multiplication (*)
cout << "a * b = " << a * b << endl;
// Binary division (/)
cout << "a / b = " << a / b << endl;
// Binary modulo (%)
cout << "a % b = " << a % b << endl;
// Binary bitwise AND (&)
cout << "a & b = " << (a & b) << endl;
// Binary bitwise OR (|)
cout << "a | b = " << (a | b) << endl;
// Binary bitwise XOR (^)
cout << "a ^ b = " << (a ^ b) << endl;
// Binary left shift (<<)
cout << "a << 1 = " << (a << 1) << endl;
// Binary right shift (>>)
cout << "a >> 1 = " << (a >> 1) << endl;
// Logical AND (&&)
cout << "(a > 0) && (b > 0) = " << ((a > 0) && (b > 0))
<< endl;
// Logical OR (||)
cout << "(a > 0) || (b > 0) = " << ((a > 0) || (b > 0))
<< endl;
// Equal to (==)
cout << "a == b = " << (a == b) << endl;
// Not equal to (!=)
cout << "a != b = " << (a != b) << endl;
// Greater than (>)
cout << "a > b = " << (a > b) << endl;
// Less than (<)
cout << "a < b = " << (a < b) << endl;
// Greater than or equal to (>=)
cout << "a >= b = " << (a >= b) << endl;
// Less than or equal to (<=)
cout << "a <= b = " << (a <= b) << endl;
return 0;
}
Output
a + b = 15 a - b = 5 a * b = 50 a / b = 2 a % b = 0 a & b = 0 a | b = 15 a ^ b = 15 a << 1 = 20 a >> 1 = 5 (a > 0) && (b > 0) = 1 (a > 0) || (b > 0) = 1 a == b = 0 a != b = 1 a > b = 1 a < b = 0 a >= ...
Binary Operators in Programming
Binary Operators are essential tools in programming that perform operations on pairs of data, enabling tasks like calculations, comparisons, logical operations, and bitwise manipulations. They are fundamental for processing and manipulating data efficiently in computer programs.
Table of Content
- What are Binary Operators?
- Basics of Binary Operators
- Binary Operator in C
- Binary Operator in C++
- Binary Operator in Java
- Binary Operator in Python
- Binary Operator in C#
- Binary Operator in Javascript
- Best Practices of Binary Operator