#include <iostream> #include <cstdint> using namespace std; class Flags { private: uint8_t bits; public: explicit Flags(uint8_t b) : bits(b) {} // Define operator~ to return a new Flags object with all 8 bits inverted friend Flags operator~(const Flags& f){ Flags new_flags(~(f.bits)); return new_flags; } uint8_t getBits() const { return bits; } }; int main() { int val; cin >> val; Flags f(static_cast<uint8_t>(val)); Flags toggled = ~f; cout << "Input=" << val << " Toggled Input=" << static_cast<int>(toggled.getBits()); return 0; }
Test Cases
Test Results
Input
0
Expected Output
Input=0 Toggled Input=255