diff --git a/src/04_UDEF/Testat/Testat.cpp b/src/04_UDEF/Testat/main_04_UDEF_e.cpp similarity index 91% rename from src/04_UDEF/Testat/Testat.cpp rename to src/04_UDEF/Testat/main_04_UDEF_e.cpp index 87f2c41..b2884fe 100644 --- a/src/04_UDEF/Testat/Testat.cpp +++ b/src/04_UDEF/Testat/main_04_UDEF_e.cpp @@ -8,10 +8,12 @@ struct BinaryOctet { bool evenParity; char bitsAsDigits[bitsPerOctet]{}; + BinaryOctet(int x = 0); BinaryOctet(const BinaryOctet&) = default; const BinaryOctet operator--(int); const BinaryOctet operator++(int); + BinaryOctet operator~(); bool operator!=(BinaryOctet &a); bool operator>=(BinaryOctet &a); BinaryOctet operator-(BinaryOctet a); @@ -51,6 +53,14 @@ const BinaryOctet BinaryOctet::operator++(int) { return operator+(*new BinaryOctet(1)); } +BinaryOctet BinaryOctet::operator~() { + BinaryOctet res; + for(int i = 0; i <= bitsPerOctet; i++) { + res.bitsAsDigits[i] = bitsAsDigits[i] == '0' ? '1' : '0'; + } + return res; +} + BinaryOctet BinaryOctet::operator+(BinaryOctet a) { BinaryOctet result; bool over = false; @@ -177,6 +187,15 @@ std::ostream &operator<<(std::ostream &os, BinaryOctet *toBePrinted) { return os; } +void printInverse(int i) { + std::cout << ~i << std::endl; +} + + +void printInverse(BinaryOctet o) { + std::cout << ~o << std::endl; +} + int main(int argc, char **argv) { std::cout << "========= init ==========" << std::endl; @@ -205,5 +224,9 @@ int main(int argc, char **argv) { d--; std::cout << "11111111-- = " << d-- << std::endl; + std::cout << "======== printInverse ============" << std::endl; + printInverse(42); + printInverse(b); + return 0; } \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6397d9a..4fd107a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,7 +10,7 @@ add_executable(03_FLOW_Testat 03_FLOW/Testat/main_mp2_FLOW_a.cpp helpers/AnsiCon add_executable(04_UDEF_MP 04_UDEF/MP/main_04_UDEF_e.cpp) target_link_libraries(04_UDEF_MP m) -add_executable(04_UDEF_Testat 04_UDEF/Testat/Testat.cpp) +add_executable(04_UDEF_Testat 04_UDEF/Testat/main_04_UDEF_e.cpp) target_link_libraries(04_UDEF_Testat m) add_executable(05_OO_MP 05_OO/MP/shapes_main.cpp helpers/AnsiConsole.cpp 05_OO/MP/Shape.cpp 05_OO/MP/Position.h 05_OO/MP/Shape.h 05_OO/MP/Point.cpp 05_OO/MP/Point.h 05_OO/MP/Circle.cpp 05_OO/MP/Circle.h 05_OO/MP/Rectangle.cpp 05_OO/MP/Rectangle.h 05_OO/MP/Scene.cpp 05_OO/MP/Scene.h)