#include <iostream>
#include <cstdint>
using namespace std;
class Flags {
private:
uint8_t bits;
public:
Flags(uint8_t b) : bits(b) {}
Flags operator~() const {
return Flags(~bits);
}
uint8_t getBits() const {
return bits;
}
};
int main() {
int val;
cin >> val;
Flags f(val);
Flags toggled = ~f;
cout << "Toggled=" << (int)toggled.getBits();
return 0;
}
Solution Details
👉 In simple words:
Normally ~ flips all the bits of an integer. By overloading it, we allow ~ to work directly on a custom class like Flags.
Significance for Embedded Developers
Input
0
Expected Output
Toggled=255