 # What does this operator "==!" do?

Hello,

I'm preparing for an exam and in the code for the exam there is an operation like this:

while(buttons ==!1) //buttons is integer
{

}

I know what "==" and "!" does, but I've never seen it being used like this.
I would assume that the ! operator turns the 1 into a false, so that the expression is equal to:
while(buttons == false) or while(buttons == 0)

Can anyone explain the meaning of this expression please?

There is no "==!" operator

You've got two operators.

So am I right that the expression is equal to while (buttons == false)?

Why would you write it the other way then?

Watnik:
Why would you write it the other way then?

Because it is an exam question?

No, this is just the code for the exam. It is not expected to read through this code...

``````while(buttons ==!1)                   //buttons is integer
{

}
``````

The only way I can make sense of that is:

``````while(buttons == !1)                   //buttons is integer
{

}
``````

As in, ‘while buttons is equal to not 1’, which is a funny way of saying ‘while buttons is not equal to 1’.

I think the more sensible way to write this would be:

``````while(buttons != 1)                   //buttons is integer
{

}
``````

PerryBebbington:
As in, ‘while buttons is equal to not 1’, which is a funny way of saying ‘while buttons is not equal to 1’.

Actually, “while buttons is equal to not 1” is “while buttons is equal to false (0)”

Here’s the comparison between == 0 and !=1:

``````void setup()
{
Serial.begin(115200);
for(int lp=0;lp<5;lp++)
{
Serial.print(lp !=1);
Serial.print(" ");
Serial.println(lp == !1);
}
}

void loop()
{
}
``````

wildbill:
Actually, "while buttons is equal to not 1" is "while buttons is equal to false (0)"

This is what I thought, too. And looking at the rest of the program it makes sense...

PerryBebbington:
As in, 'while buttons is equal to not 1', which is a funny way of saying 'while buttons is not equal to 1'.
I think the more sensible way to write this would be:

``````while(buttons != 1)                   //buttons is integer
``````

{

}

well technically not quite.

in C or C++ the expression `!1`t evaluate to `0` so this means while buttons is exactly equal to 0.
if` buttons` is worth 2 then it's not equal to 1 but it's not equal to 0 either.

Well technically not quite.

in C or C++ the expression !1t evaluate to 0 so this means while buttons is exactly equal to 0.
if button is worth 2 then it's not equal to 1 but it's not equal to 0 either.

I wondered something like that after I posted. I'm glad this is not my exam question!

A button can be either at 'closed' condition or at 'open' condition. 'button is exactly equal to 0' -- this statement could be syntactically correct but not semantically? For exam question, it is acceptable and fine!

GolamMostafa:
A button can be either at 'closed' condition or at 'open' condition.

Technically - the switch attached to the button can be either closed or open. The button can be pressed or not pressed and because of bouncing there is not always direct correlation between the state of one and the other... J-M-L:
well technically not quite.

in C or C++ the expression `!1`t evaluate to `0` so this means while buttons is exactly equal to 0.
if` buttons` is worth 2 then it's not equal to 1 but it's not equal to 0 either.

That's not quite correct. The not operator takes a boolean and returns a boolean.

J-M-L:
Technically - the switch attached to the button can be either closed or open. The button can be pressed or not pressed and because of bouncing there is not always direct correlation between the state of one and the other...

We have button ; we have switch ;the button activates the switch. Thus as per above quote, the button and switch are two different things; if so, then what would be the name of this one: ?   You show a picture of what looks like a push button, but the symbol for a switch.
(A push button symbol looks like an inverted T over two terminals)

a single pole single throw actuator ? Watnik,
In case you have not noticed, the discussion has wandered off from what you originally asked about. This happens on forums, and not just this one. Read with interest or ignore as you see fit, but don't let it bother you.

PerryBebbington:
Watnik,
In case you have not noticed, the discussion has wandered off from what you originally asked about. This happens on forums, and not just this one. Read with interest or ignore as you see fit, but don't let it bother you.

indeed

@Watnik - sorry for the digression

J-M-L:
a single pole single throw actuator ? I must salute! 