84. Register8 Equality Operator

#include <iostream>
#include <cstdint>
using namespace std;

class Register8 {
private:
    uint8_t value;
public:
    Register8(uint8_t v) : value(v) {}

    bool operator==(const Register8& other) const {
        return value == other.value;
    }

    uint8_t getValue() const {
        return value;
    }
};

int main() {
    int a, b;
    cin >> a >> b;

    Register8 r1(static_cast<uint8_t>(a));
    Register8 r2(static_cast<uint8_t>(b));

    if (r1 == r2)
        cout << "Equal";
    else
        cout << "Not Equal";

    return 0;
}

Explanation & Logic Summary:
The overloaded == operator compares the internal 8-bit values of two Register8 objects.

If both stored values are identical, it returns true; otherwise, it returns false.

This allows register objects to be compared naturally using:

if (reg1 == reg2)

Firmware Relevance & Real-World Context:

  • Mirrors real firmware scenarios where hardware registers are compared
  • Reinforces operator overloading for cleaner low-level APIs
  • Emphasizes fixed-width integer types, critical in embedded systems
  • Encourages readable, maintainable firmware code

 

 


 

Loading...

Input

10 10

Expected Output

Equal