// demo_03_twos_complement.cpp

/*
 * @topic T00244 Binary numbers
 * @brief <br />A program demonstrating negation algorithm<br /><br />
*/

#include <iostream>

int negate( int data )
{
    // Demonstrates negation micro-algorithm
    // The following code is equivalent of data = -data:
    data = ~data;     // btwise NOT operator flips all bits
    data = data + 1; // add one
    return data;
}

int main()
{
    for (;;) {
        int data = 0;
        std::cout << "Enter a number: ";
        std::cin >> data;
        std::cout << negate( data ) << "\n\n";
    }
    return 0;
}