Converting a number to tens and ones comparison

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Converting a number to tens and ones comparison

Post by Kenrix2 »

This is a comparison of three different digit conversion methods to get the tens and ones digit which I use for two digit
seven segment displays (both led and lcd glass). I needed to determine the best method to use depending on my application.
Here are the results of my comparison tests which I thought I would share. The different conversion programs are attached.

Using IF less than to determine the digits
Pros:
good conversion speed, 21us to 62us (average is about 43us, the higher the number the longer it takes)
It simulates in Flowcode
Uses little ROM space
Cons:
Conversion time is not consistent
Takes up a lot of your screen real estate
Takes awhile to setup in your program

Using a ROM lookup table
Pros:
Does not not take up much screen real estate in you program
Somewhat easy to add to your program
Conversion time is the same for any value
Cons:
Slow conversion speed, 110us
Does not simulate in Flowcode (It might in V6 but I am not sure)
Uses a lot of ROM space

Using a RAM lookup table
Pros:
Excellent conversion speed, only 32us (as expected this is the fastest)
It simulates in Flowcode
Conversion time is the same for any value
Cons:
Takes up a lot of RAM (obviously)
Takes awhile to setup
Takes up a bit more of your screen real estate than the ROM LUT
Adds a whopping 207us to the power on reset time vs the others
Uses a lot of ROM Space

If anyone has a another method to convert a number (0 to 99) into tens and ones digits, and wouldn't mind sharing, I would
like to see it.
Attachments
Two_Digit_RAM_LUT.fcf
(16.64 KiB) Downloaded 248 times
Two_Digit_ROM_LUT.fcf
(7 KiB) Downloaded 242 times
two_digit_using_if_less_than.fcf
(11.58 KiB) Downloaded 247 times

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Converting a number to tens and ones comparison

Post by Spanish_dude »

There's another, easy and short, method you missed:

Code: Select all

int number, ones, tens;

if (number >= 100)
    number = 0;
else
{
    ones = number % 10; // (MOD)
    tens = number / 10;
    number++;
}
- Nicolas

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: Converting a number to tens and ones comparison

Post by Kenrix2 »

Thank you for your response Spanish_Dude. The method you posted is probably the simplest and easiest to use. It can also be put into a normal Flowcode calculation box for simulation within Flowcode. It's a great default method. However, a speed test shows it is dead last at 260us. Ouch!

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Converting a number to tens and ones comparison

Post by Spanish_dude »

Yes, multiplications and divisions are very slow.

- Nicolas

Post Reply