Comparing 2 UInt values

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
Coensk
Posts: 10
Joined: Tue Mar 14, 2017 10:38 am
Has thanked: 4 times
Contact:

Comparing 2 UInt values

Post by Coensk »

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

User avatar
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

Post by Benj »

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.
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" ?
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.

If you attach your program then we can have a look and maybe provide a fix for you.

Coensk
Posts: 10
Joined: Tue Mar 14, 2017 10:38 am
Has thanked: 4 times
Contact:

Re: Comparing 2 UInt values

Post by Coensk »

Hello Benj,

I already solved the "array index is out of bounds" error which was a silly question.. :roll:

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 259 times

User avatar
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

Post by SimonB »

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 8)

Simon
Attachments
2103.fcfx
(17.56 KiB) Downloaded 274 times

Post Reply