‣
#include <iostream>
using namespace std;
int main(){
int x = 0x3DBA;
// **SET** bit num **10**, **15**
// Now we will make the (**mask**) to apply the **SET**
// The **bit num 10** is inside (**D**) => 13 = 1101 => mask = 0010 => 2
// The **bit num 15** is inside (**3**) = 0011 => mask = 0100 => 4
// Now **replace** the bits you changed and put the **remainder** with **0**
int mask = 0x4200;
// If you want to do **SET** , Use => **OR (|)**
x = x | mask; // equal => x |= mask
cout << hex << x << endl; // Output : 7FBA
}
#include <iostream>
using namespace std;
int main(){
int y = 0x5E53;
// **RESET** for bit num **5**, **11**
// Now we will make the (**mask**) to apply the **RESET**
// The **bit num 5** is inside (**5**) = 0101 => mask = 1110 => E
// The **bit num 11** is inside (**E**) = 1110 => mask = 1011 => B
// Now **replace** the bits you changed and put the **remainder** with **1**
int mask = 0xFBEF;
// If you want to do **RESET** , Use => **AND (&)**
y &= mask; // => equal => x |= mask
cout << hex << y << endl; // Output : 5A43
}
#include <iostream>
#include <bitset>
using namespace std;
int main(){
int x = 0x3DBA;
// **SET** for bit num **10**, **15**
// **RESET** for bit num **5**, **11**
int maskForSet = 0x4200;
int maskForReset = 0xFBAF;
cout << "The value of X before Set & Reset : \\n" << bitset<16>(x);
x |= maskForSet;
x &= maskForReset;
cout << "\\nThe value of X after Set & Reset : \\n" << bitset<16>(x);
}
#include <iostream>
#include <bitset>
****using namespace std;
int main() {
int a = **0b**1111; // Declare **Binary** number
int b = 15; // Declare **Decimal** number
int c = **0x**F; // Declare **Hexadecimal** number
int d = **0**17; // Declare **Octal** number
cin >> dec >> b; // Take **decimal** number
cin >> hex >> c; // Take **Hexadecimal** number
cin >> oct >> d; // Take **Octal** number
cout << bitset<4>(b) << endl; // print in **Binary**
cout << dec << a << endl; // print in **decimal**
cout << hex << c << endl; // print in **hexadecimal**
cout << oct << d << endl; // print in **Octal**
}
#include <bitset> // Import Library
cout << bitset<8>(x);
// ↓ ↓ ↓
// [lib. name] ↓ [var. name]
// ↓
// [Number of Digits you want to print]