Coders Packet

Comparison of numbers in C++

By Subalaxmi C

Comparison of intergers without the help of any arithmetic operators or comparison operators.

XOR is a bitwise operator which stands for Exclusive OR. 

For performing a XOR operation we need the digits in binary form. In case if they're in interger form we need to convert them into binary form i.e. into 1's and 0's. 

When converted into binary form we need to add 0's in the front if necessary. XOR is the operation of adding all the binary digits and writing them together. 

In XOR operation, when adding

If both the bits are 1 then the XOR' ed bit is 0

If both the bits are 0 then the XOR' ed bit is 0 

If one of the bit is 1 and the other bit is 0 then the XOR' ed bit is 1.

So, in the case of this progeam, during the if case the compiler checks if both the bits are equal or not. If they are equal then the XOR' ed bit becomes 0 and the if loop fails and the compiler goes to the else loop and it gets executed. 

Download project

Reviews Report

Submitted by Subalaxmi C (SubaChidambaram)

Download packets of source code on Coders Packet