Adding and manipulating large numbers

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Desdewit
Posts: 130
Joined: Sat Feb 26, 2011 4:26 am
Location: South Africa
Has thanked: 25 times
Been thanked: 11 times
Contact:

Adding and manipulating large numbers

Post by Desdewit »

Hi Ben

So far my instrument are working and adding the numbers like it should but if I use numbers larger than that of an int. then I get problems.
what must I do to add numbers like 50000 & 80000 & display it on lcd again

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: 7bit ascii with odd parity

Post by Benj »

Hello,

To do this at the moment in Flowcode you will have to resort to using C code and you would also have to use the code customization feature to edit the LCD print number function.

Example C code.

unsigned long varx; //creates a 32-bit variable named varx that can only be positive 0 to 4294967296.
signed long varx; //creates a 32-bit variable named varx that can be positive or negative -2147483648 to 2147483647.

Desdewit
Posts: 130
Joined: Sat Feb 26, 2011 4:26 am
Location: South Africa
Has thanked: 25 times
Been thanked: 11 times
Contact:

Adding 6 digit numbers

Post by Desdewit »

Hi Ben

If I want to use the signed long varx; to add/subtract two 6 digit numbers like you said, must I replace the x with the varable holding one of the numbers?
What must I change in the LCD print number function?

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: Adding 6 digit numbers

Post by Benj »

Hello,

To add numbers into a long you would do something like this.

signed long calc = (long) FCV_A + FCV_B;

where a and b are variable names in Flowcode.

The (long) is a type casting and is required to specify that the calculation should be 32-bit.

Attached is a version of the v4 LCD component for PIC that has an extra function to print out long numbers.

Let me know if any problems.
Attachments
PIC_gLCD.c
(33.77 KiB) Downloaded 255 times

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Adding and manipulating large numbers

Post by medelec35 »

Hi Ben,
I have a question regarding signed long calc.

What would be the difference in room taken up by signed long calc and float?

I believe they are both 4 Bytes?

If that is the case, would it be easier to use float instead of C declarations and C retrieval?

I'm not disagree with what you are saying, it's just something I would like to learn about.
Martin

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: Adding and manipulating large numbers

Post by Benj »

Hello Martin,

You are correct that the float and long variables are both 32-bit and also that you could use a float to store the long number. Main reason I didn't mention it was because I forgot about it :D However there is one downside in that you have to use the BoostC float functions to manipulate floats whereas longs can be manipulated directly without the need for the wrapper functions. This means you could manipulate longs in your interrupt and main program whereas you cannot really do this with floats.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Adding and manipulating large numbers

Post by medelec35 »

Benj wrote:This means you could manipulate longs in your interrupt and main program whereas you cannot really do this with floats.
Thanks Ben. I did not know that.. Useful information.
Glad I asked now :)
Martin

Post Reply