I was asked in an interview : how to convert 0 to 1 and 1 to 0. I answered :
if
and switch
Are there any other approach?
Simple arithmetic:
x = 1 - x;
Actually, there are an infinite number of polynomials that will map 1 to 0 and vice versa. For example:
x = x * x * x * x * x - x * x * x * x + x * x - 2 * x + 1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With