Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can You Use Arithmetic Operators to Flip Between 0 and 1

Tags:

algorithm

Is there a way without using logic and bitwise operators, just arithmetic operators, to flip between integers with the value 0 and 1?

ie. variable ?= variable will make the variable 1 if it 0 or 0 if it is 1.

like image 698
Daniel Sopel Avatar asked Nov 03 '10 03:11

Daniel Sopel


People also ask

Which is not arithmetic operator?

The string concatenation operator (&) is not an arithmetic operator, but in precedence, it does fall after all arithmetic operators and before all comparison operators.

What are the 5 arithmetic operators?

Definition. The arithmetic operators perform addition, subtraction, multiplication, division, exponentiation, and modulus operations.

Which of the following can be operators of arithmetic operators?

These operators are + (addition), - (subtraction), * (multiplication), / (division), and % (modulo).


1 Answers

x = 1 - x 

Will switch between 0 and 1.

like image 81
Reverend Gonzo Avatar answered Oct 07 '22 22:10

Reverend Gonzo