Page 1 of 1

Adding and manipulating large numbers

Posted: Sat Mar 26, 2011 9:01 am
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

Re: 7bit ascii with odd parity

Posted: Mon Mar 28, 2011 10:44 am
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.

Adding 6 digit numbers

Posted: Thu Apr 07, 2011 6:08 pm
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?

Re: Adding 6 digit numbers

Posted: Fri Apr 08, 2011 10:03 am
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.

Re: Adding and manipulating large numbers

Posted: Fri Apr 08, 2011 1:05 pm
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.

Re: Adding and manipulating large numbers

Posted: Fri Apr 08, 2011 1:15 pm
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.

Re: Adding and manipulating large numbers

Posted: Fri Apr 08, 2011 2:35 pm
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 :)