AND function in ESP32! SOLVED! Use && instead

For general Flowcode discussion that does not belong in the other sections.
Post Reply
jgu1
Posts: 615
http://meble-kuchenne.info.pl
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 507 times
Been thanked: 132 times

AND function in ESP32! SOLVED! Use && instead

Post by jgu1 »

Hi!

I am playing with a project with an Ili9341 and an ESP32 with XPT2046

If I use an IF contain this: X > 34 AND X < 130 AND Y > 110 AND Y < 65 I get an error when compiling look like the ESP32 don´t like AND. It work with arduino and Arm I also try with &

Is there other command for AND in ESP32?

****** SOLVED***** Search in the net, USE && :D :D

Thank´s in advance

Jorgen

medelec35
Matrix Staff
Posts: 1451
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 512 times
Been thanked: 472 times

Re: AND function in ESP32! SOLVED! Use && instead

Post by medelec35 »

Hi, Jorgen.
Just to clarify, You always use && instead of AND in any decisions when comparing values.
&& is Logical.
AND is bitwise.
Also for when comparing values use the following logical operators:
|| = OR (| is the pipe key next to Z on a UK keyboard).
! = NOT
Martin

jgu1
Posts: 615
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 507 times
Been thanked: 132 times

Re: AND function in ESP32! SOLVED! Use && instead

Post by jgu1 »

Hi MArtin!

Thank you very much. Learn some new today :D

So AND versus is not equal to && I have earlyer used OR and AND in Arduino and Pic whith good luck.

Thank´s again I will be aware in the future ;)

Br Jorgen

medelec35
Matrix Staff
Posts: 1451
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 512 times
Been thanked: 472 times

Re: AND function in ESP32! SOLVED! Use && instead

Post by medelec35 »

Hi Jorgen,
Your'e welcome.
jgu1 wrote:
Tue Mar 09, 2021 6:29 pm
So AND versus is not equal to &&
No definitely not the same.
The AND OR NOT etc for bit wise manipulation only.
Martin

Steve-Matrix
Matrix Staff
Posts: 1253
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: AND function in ESP32! SOLVED! Use && instead

Post by Steve-Matrix »

The bitwise AND (&) can sometime appear to work like the logical &&, but not always. I think it's always safer to avoid "AND", "OR", etc., and always use the correct symbol (e.g. & or &&) to avoid confusion.

For example, consider three byte variables (X=1, Y=2, Z=3) in the following decisions:

"if (X & Y)" is false, but "if (X & Z)" is true (the bitwise operator results in "if 0" and "if 1" respectively).

"if (X && Y)" is true, and "if (X && Z)" is true (X, Y and Z are all non-zero and converted to "true" when using the logical operators).

jgu1
Posts: 615
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 507 times
Been thanked: 132 times

Re: AND function in ESP32! SOLVED! Use && instead

Post by jgu1 »

Hi Martin and Steve!

Thank you very much. Yes , I though it doesn´t matter how to use ;) And as Steve said it sometimes work I Expeince it work with AND OR ect. It have always used this. I am glad to know your explanation and of course, from now always use you advice.

But please tell me, why sometime use two &,|.

Eks:

If A & B =2

If A && B =2

Br Jorgen

LeighM
Valued Contributor
Posts: 401
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 71 times
Been thanked: 217 times

Re: AND function in ESP32! SOLVED! Use && instead

Post by LeighM »

Google C operators 😊

Steve-Matrix
Matrix Staff
Posts: 1253
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: AND function in ESP32! SOLVED! Use && instead

Post by Steve-Matrix »

jgu1 wrote:
Thu Mar 11, 2021 5:57 pm
But please tell me, why sometime use two &,|.
Single is boolean operation: "10 & 7" => 2

Double is a logical operation: "true && false" => false

A further complication is that in logical operations (e.g. in the decision icon) any non-zero number is converted to "true" and zero is converted to "false". So "if (10 & 7)" becomes "if (2)" which becomes "if (true)".

But "if (10 & 5)" becomes "if (0)" which becomes "if (false)".

But Leigh is correct - there are lots of better explanations elsewhere on the internet!

LeighM
Valued Contributor
Posts: 401
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 71 times
Been thanked: 217 times

Re: AND function in ESP32! SOLVED! Use && instead

Post by LeighM »

This one is very good, which explains its top ranking :)
https://www.tutorialspoint.com/cprogram ... rators.htm

jgu1
Posts: 615
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 507 times
Been thanked: 132 times

Re: AND function in ESP32! SOLVED! Use && instead

Post by jgu1 »

Thank you Leigh. As Steve said Google it ,I am in full speed and begin to understand :D

I will have a look at your link, thank you and have a nice weekend.

Br Jorgen

Post Reply