0
what does this code do?
https://code.sololearn.com/c4ot0sKPOC00 it's the code for function that returns false if both of inputs are even or odd, otherwise it returns true. but , I didn't understand how does it works? can someone explain it to me?
3 Answers
0
! ! ( ( ÏŸ & 1) ^ (1 & Ïż ) )
The function uses bitwise & (and) to examine the lowest bit, which is a determinant whether a number is odd or even. (1 indicates odd; 0, even).
It performs exclusive or ^ to determine whether they are different. Exclusive or is equivalent to the logical comparison operator !=. (True means not equal; False, equal)
The ! ! (not not) operators are used to convert the binary result of ^ into a Boolean True/False. The first ! converts the result into Boolean type, but undesirably negates the value. The second ! negates the value again to restore the original meaning.
You would get the same result with
( ÏŸ & 1) != (1 & Ïż )
But it wouldn't be as picturesque.
- 1
Its nothing more than comparison of two numbers