Hi,
I am using a decision block to see if the value stored in a variable is from 1 to 10.
Here is the line I have in the decision block.
Command_BYTE >= 1 AND Command_BYTE <= 10
I read an EEPROM address and get the value 54, which is NOT within the range I am testing.
I issue the STEP INTO command to step through the sequence and I alway take the YES path even though the variable is NOT in the range specified.
What am I doing wrong?
Thanks
Ron
Decision Block Problem
- Steve
- Matrix Staff
- Posts: 3427
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Chet's suggestion is right. The "&&" (borrowed from 'C') is used for a "logical AND" whereas the "AND" term is for a "bitwise AND" (the reason for this is largely historic - the early versions of Flowcode only had the latter "bitwise" operators and I wanted to introduce the "logical" AND/OR without breaking compatibility with user's previous code).
I would also suggest putting brackets around the expression to improve readibility, like this:
I would also suggest putting brackets around the expression to improve readibility, like this:
Code: Select all
(Command_BYTE >= 1) && (Command_BYTE <= 10)
All Better
Hi Chet,
It was late when I was working on this. Every other decision block I was testing for a range was &&. All I remember was reading the decision help file and I must of changed it to AND just to see what would happen.
You are 100% correct.... Thanks
Steve,
Good catch on the readability, I like well formatted code, so much easier to read and debug.
Pardon my lack of knowledge - What is ""bitwise AND"?
Thanks again,
Ron
It was late when I was working on this. Every other decision block I was testing for a range was &&. All I remember was reading the decision help file and I must of changed it to AND just to see what would happen.
You are 100% correct.... Thanks
Steve,
Good catch on the readability, I like well formatted code, so much easier to read and debug.
Pardon my lack of knowledge - What is ""bitwise AND"?
Thanks again,
Ron
- Steve
- Matrix Staff
- Posts: 3427
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Here's a quick example of a bitwise AND on two numbers, 5 and 6:
In binary, 5 = 101 and 6 = 110.
If you perform a bitwise AND on these two numbers, you AND-together the bits of each number like this:
So the answer is 4 (100 in binary), i.e. 5 AND 6 = 4.
Think of it in terms of AND gates in digital logic.
There is an equivalent binary-OR which works in a similar way: 5 OR 6 = 7.
And an exclusive OR: 5 XOR 6 = 3
And a NOT: NOT 6 = 249 (11111001 in binary)
In binary, 5 = 101 and 6 = 110.
If you perform a bitwise AND on these two numbers, you AND-together the bits of each number like this:
Code: Select all
101
110
---
100
Think of it in terms of AND gates in digital logic.
There is an equivalent binary-OR which works in a similar way: 5 OR 6 = 7.
And an exclusive OR: 5 XOR 6 = 3
And a NOT: NOT 6 = 249 (11111001 in binary)
- Steve
- Matrix Staff
- Posts: 3427
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Hello Chet,
Sorry you've had to wait a long time for a reply - I've been on holiday.
If you have a program that works in v2 but does not in v3, then please send it to me and I'll have a look.
One of the main porting issues has been to do with the change in the C compiler that Flowcode uses. In almost all cases so far, user's own C or ASM code has been the issue (embedded within a C icon).
Sorry you've had to wait a long time for a reply - I've been on holiday.
If you have a program that works in v2 but does not in v3, then please send it to me and I'll have a look.
One of the main porting issues has been to do with the change in the C compiler that Flowcode uses. In almost all cases so far, user's own C or ASM code has been the issue (embedded within a C icon).