is there a way to improve the speed of the function?
The modulo function is not the fastest function. Avoid it, if you can. Once you've determined the hours value, subtract that value (times the appropriate factor) from the initial value. What is left is the time in minutes and seconds.
Determine minutes, subtract that value (times the appropriate factor) from the initial value. What is left is the time in seconds.
The trick to this is to try to use the minimum number of long divisions (and note that % remainder is a division).
My attempt shaved off a microsecond on my Duemilanove.
void SplitTime3()
{
int hm = GPS_Time/100000L;
unsigned int rem = GPS_Time%100000L;
HH = hm/100;
MM = hm%100;
SS = rem/1000;
}
Time:191us
HH:23
MM:59
SS:59
Time:124us
HH:23
MM:59
SS:59
Time:123us
HH:23
MM:59
SS:59
Time:122us
HH:23
MM:59
SS:59
You will probably find that you can have fast or small code, but not both.
void SplitTime4()
{
unsigned long S = GPS_Time / 1000;
HH = S/10000; // 23
unsigned int T = S-HH*10000; //5959
// MM = (T *5243L >> 19); // 95us but unclear
MM = T/100; // 96us
SS = T - MM*100;
}
This probably isn't going to make a lot of sense all by itself Nick. Why not occasionally add something constructive instead of just trashing everybody's typo mistakes.
I disagree.
Nick is an experienced member here, and if he says there's something wrong with your code, you'd better go and find out what it is.
And if you do expend the effort, you can be assured that the answer will stick with you much better than if you'd been given the answer.
Delta_G:
This probably isn't going to make a lot of sense all by itself Nick. Why not occasionally add something constructive instead of just trashing everybody's typo mistakes.
I'm not trashing it. It may have slipped by - that is, it didn't occur to him/her to closely look at that line. Some early responses didn't pick it up.
I'm trying to encourage people to think for themselves rather than server up pre-canned answers.
Why not occasionally add something constructive ...
I believe I often add constructive things. Ask other people here.
Sometimes I get the impression though that some posters bang some code on the site here, say "it doesn't work" and sit back waiting for the fixed code to be posted for them. Hinting at problem areas is supposed to get the old gray matter working, so that next time, they can solve it for themselves.
AWOL:
Trivial this time, yes, but we've had hard to spot errors caused by misplaced line continuations like this one.
Well I'd say he just pointed at it using a single line. It is common experience indeed to see some "trashing" become added to posts, even if the participants really give a good contribution.
If the people doing it are professional and also contribute innovation, ideas, not just criticism, I don't mind it.
Often I'd read a post again for lexical typo's and correct them.