Untitled Document (49)
Untitled Document (49)
VALUES OF 4 BIT
Decimal Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111
=================================
Bitwise OR (|)
● Description: Compares each bit and returns 1 if at least one bit is 1.
=======================
● Description: Compares each bit and returns 1 if one of the bits is 1 (but not
both).
================
Here's a table comparing the left shift and right shift operations, illustrating their effects on
binary values:
Key Points:
int main() {
cout << "After left shifting by " << shiftBy << " positions:" << endl;
cout << "Resulting number: " << result << endl; // Decimal result
cout << "Binary representation: " << bitset<8>(result) << endl; // Display
binary
return 0;
=======================
RIGHT SHIFT
#include <iostream>
#include <bitset>
using namespace std;
int main() {
int number = 20; // Binary: 0001 0100
int shiftBy = 2; // Number of positions to shift
return 0;
}
======================================
int main() {
int a = 5; // Binary: 0101
int b = 3; // Binary: 0011
cout << "a & b: " << (a & b) << endl; // Bitwise AND
cout << "a | b: " << (a | b) << endl; // Bitwise OR
cout << "a ^ b: " << (a ^ b) << endl; // Bitwise XOR
cout << "~a: " << (~a) << endl; // Bitwise NOT
cout << "a << 1: " << (a << 1) << endl; // Left shift
cout << "a >> 1: " << (a >> 1) << endl; // Right shift
return 0;
}
a & b: 1
a | b: 7
a ^ b: 6
~a: -6
a << 1: 10
a >> 1: 2
=================================================