#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a hexadecimal number: ";
cin >> hex >> num; // read as hex
// Check last 2 bits: (num & 0b11) == 0b11
cout << (((num & 0x3) == 0x3) ? "true" : "false") << endl;
return 0;
}
...................................................................................
.............
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
string hexNum;
cout << "Enter a hexadecimal number: ";
cin >> hexNum;
// Remove "0x" or "0X" if user enters it
if ([Link]() > 1 && hexNum[0] == '0' && (hexNum[1] == 'x' || hexNum[1] ==
'X')) {
hexNum = [Link](2);
}
// Reverse the hex string (nibble order)
reverse([Link](), [Link]());
cout << "Reversed nibble order: 0x" << hexNum << endl;
return 0;
}
...................................................................................
.........................
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
int main() {
unsigned int num;
cout << "Enter a hexadecimal number (32-bit): ";
cin >> hex >> num;
// Rotate bytes (reverse byte order)
short rotated = ((num & 0x00FF) << 8) | ((num & 0xFF00) >> 8);
cout << "Original: 0x" << hex << uppercase << setw(4) << setfill('0') << num <<
endl;
cout << "Rotated : 0x" << hex << uppercase << setw(4) << setfill('0') <<
rotated << endl;
return 0;
}
...................................................................................
......................................
CAFE = 1100 1010 1111 1110