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
Adding and manipulating large numbers
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: 7bit ascii with odd parity
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.
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.
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
-
- 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
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?
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?
- 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
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.
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
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
-
- 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
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.
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
- 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
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
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.
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
![Very Happy :D](./images/smilies/icon_biggrin.gif)
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
-
- 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
Thanks Ben. I did not know that.. Useful information.Benj wrote:This means you could manipulate longs in your interrupt and main program whereas you cannot really do this with floats.
Glad I asked now
![Smile :)](./images/smilies/icon_smile.gif)
Martin