Hello,
In my program I'm trying to compare 2 variables "Val[10]" and "Preval[10]". Both variables consist of 10 bits.
I'm trying to see which bit changed by using the XOR command and storing the final value in a third variable "Change[10]".
I'm kind of new to Flowcode so can anyone explain me why I'm getting the "incompatible operands for operation" error when using the Calculation command "Change = Val XOR Preval" ?
Also when i try "Change[3] = Val[3] XOR Preval[3]" I'm getting the "Array index is out of bounds" error..
Coensk
Comparing 2 UInt values
Moderator: Benj
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Comparing 2 UInt values
Hello Coensk,
The notation of a number in square brackets sets how many elements are in an array not how many bits are in the variable.
An INT variable is always 16 bits.
An INT[10] variable is an array of 10 x 16 bit values.
If you attach your program then we can have a look and maybe provide a fix for you.
The notation of a number in square brackets sets how many elements are in an array not how many bits are in the variable.
An INT variable is always 16 bits.
An INT[10] variable is an array of 10 x 16 bit values.
I'm guessing this is because the variables are declared as arrays and then you are trying to manipulate the array as a whole which is not valid syntax. If you edit the variables so they are no longer arrays (simply remove the square brackets and number from the variable name) then it should work as expected.I'm kind of new to Flowcode so can anyone explain me why I'm getting the "incompatible operands for operation" error when using the Calculation command "Change = Val XOR Preval" ?
If you attach your program then we can have a look and maybe provide a fix for you.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Comparing 2 UInt values
Hello Benj,
I already solved the "array index is out of bounds" error which was a silly question..
The program is working as intended right now, I changed the datatype to Bool, but I have to do the calculation for each bit of the array (Change[2] = Val[2] XOR Preval[2]) while i was trying to manipulate the whole array as you say.
Thanks for your help, I added my program as attached file anyway for if you might have some suggestions.
Coensk
I already solved the "array index is out of bounds" error which was a silly question..
The program is working as intended right now, I changed the datatype to Bool, but I have to do the calculation for each bit of the array (Change[2] = Val[2] XOR Preval[2]) while i was trying to manipulate the whole array as you say.
Thanks for your help, I added my program as attached file anyway for if you might have some suggestions.
Coensk
- Attachments
-
- 2103.fcfx
- (16.02 KiB) Downloaded 260 times
- SimonB
- Posts: 49
- Joined: Thu Oct 15, 2015 10:08 am
- Has thanked: 15 times
- Been thanked: 30 times
- Contact:
Re: Comparing 2 UInt values
Hi Coensk,
I just had a quick look at your program and probably you will want to be using a byte rather than a bool. A bool generally only has 2 values; True or False (0 or 1). If you want to store any value other than that then you should use other data types. Also there are easier ways to iterate through each item in your arrays. The best way to do this is to use a loop with a counter that increments on each loop and then use that counter to index in to the array. I have modified your program to do these things so you can take a look at what I mean. In each loop I use a variable called 'x' that counts from 0 to 9 and I then use that in the array instead of manually entering each number. Take a look and see
Simon
I just had a quick look at your program and probably you will want to be using a byte rather than a bool. A bool generally only has 2 values; True or False (0 or 1). If you want to store any value other than that then you should use other data types. Also there are easier ways to iterate through each item in your arrays. The best way to do this is to use a loop with a counter that increments on each loop and then use that counter to index in to the array. I have modified your program to do these things so you can take a look at what I mean. In each loop I use a variable called 'x' that counts from 0 to 9 and I then use that in the array instead of manually entering each number. Take a look and see
Simon
- Attachments
-
- 2103.fcfx
- (17.56 KiB) Downloaded 276 times