long numbers
Archiver
Posts: 46,084
Couldn't you use two words and just multiply them together to get the final
product?
-Rob
Original Message
From: Jonathan Millard <jonm@p...>
To: <basicstamps@egroups.com>
Sent: Tuesday, December 12, 2000 10:34 AM
Subject: [noparse][[/noparse]basicstamps] long numbers
> Hi everyone,
>
> Can anyone tell me how to use long numbers.
>
> A word can only store a number upto 65535.
>
> I have designed a machine that requires 2 counters. One that counts
> the number of operations it has completed in this run, which may have
> upto 5 digits i.e. 99999 and the other that may have millions of
> operations i.e. 99,999,999.
> how do i get past the 65535? And how do I store the results in the
> EEprom?
>
> The project is late and I'm getting hasle from the MD, so any help
> gratefully recieved.
>
> Regards
>
> Jon
>
>
>
>
>
product?
-Rob
Original Message
From: Jonathan Millard <jonm@p...>
To: <basicstamps@egroups.com>
Sent: Tuesday, December 12, 2000 10:34 AM
Subject: [noparse][[/noparse]basicstamps] long numbers
> Hi everyone,
>
> Can anyone tell me how to use long numbers.
>
> A word can only store a number upto 65535.
>
> I have designed a machine that requires 2 counters. One that counts
> the number of operations it has completed in this run, which may have
> upto 5 digits i.e. 99999 and the other that may have millions of
> operations i.e. 99,999,999.
> how do i get past the 65535? And how do I store the results in the
> EEprom?
>
> The project is late and I'm getting hasle from the MD, so any help
> gratefully recieved.
>
> Regards
>
> Jon
>
>
>
>
>
Comments
Can anyone tell me how to use long numbers.
A word can only store a number upto 65535.
I have designed a machine that requires 2 counters. One that counts
the number of operations it has completed in this run, which may have
upto 5 digits i.e. 99999 and the other that may have millions of
operations i.e. 99,999,999.
how do i get past the 65535? And how do I store the results in the
EEprom?
The project is late and I'm getting hasle from the MD, so any help
gratefully recieved.
Regards
Jon
There are several ways around this:
1) Detect roll over:
x0 var word
x1 var word
tmp var word
x0=0
x1=0
' add 1 to count
tmp=x0
x0=x0+1
if tmp<x0 then noover
x1=x1+1 ' add carry
noover:
' keep going
2) Change your count to a two parter. Count say 100's of operations
ct100 var word
ct var word
ct100=0
ct=0
' add 1 to count
ct=ct+1
if ct<100 then noover
ct100=ct100+(ct/100) ' save 100s part
ct=ct//100 ' get remainder
noover:
This is nice because you can display the result easily:
debug dec ct100, dec2 ct
To store these in EEPROM you have to get the byte in and out:
WRITE 0,ct.lowbyte
WRITE 1,ct.highbyte
WRITE 2,ct100.lowbyte
WRITE 2,ct100.highbyte
Both of these routines could be simplified by checking for a known number
since you are always adding 1, but I wrote them to be more general-purpose
so you could replace the 1 with anything you want. Didn't test them, so be
careful.
Just for a plug, a PAK-I or PAK-II floating point coprocessor handles 24-bit
integers (as floating point numbers) plus you get floating point.
Regards,
Al Williams
AWC
* NEW: PAK-I now operates at 20MHz! http://www.al-williams.com/awce/pak1.htm
>
Original Message
> From: Jonathan Millard [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=Oxho8qgM_LpMBxNoJMuvWVFEjX7aKT5Xp-tzhiWOiyy5AK4qIqX2BHTSbA_UUXF1XxVC83AOvKgHB-s]jonm@p...[/url
> Sent: Tuesday, December 12, 2000 9:35 AM
> To: basicstamps@egroups.com
> Subject: [noparse][[/noparse]basicstamps] long numbers
>
>
> Hi everyone,
>
> Can anyone tell me how to use long numbers.
>
> A word can only store a number upto 65535.
>
> I have designed a machine that requires 2 counters. One that counts
> the number of operations it has completed in this run, which may have
> upto 5 digits i.e. 99999 and the other that may have millions of
> operations i.e. 99,999,999.
> how do i get past the 65535? And how do I store the results in the
> EEprom?
>
> The project is late and I'm getting hasle from the MD, so any help
> gratefully recieved.
>
> Regards
>
> Jon
>
>
>
Similar to what Al suggested, this one counts up to 10000 in the
low word, and then extends the count up to 655350000 in the high word.
x0 var word ' low word of the count
x1 var word ' high word
x0=9990 ' arbitrary starting value
loop:
x0=x0+1//10000 ' up to 9999, then roll to 0
x1=x1 + 1 -(x0 max 1) ' ten-thousands
' note the term in () is =0 only when x0=0, otherwise =1
debug dec x1,dec4 x0,cr
next
-- Tracy Allen
http://www.emesystems.com/BS2math6.htm <-- more double precision math
> >
Original Message
> > From: Jonathan Millard [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=ZY0Qf3aisUIGpbCtY2x1tpeTbqUjcOdD-HWNtA-U__jOfQphGi0bA-IddNAs-0BRT5s7vS8NH2Ez1A]jonm@p...[/url
> > Sent: Tuesday, December 12, 2000 9:35 AM
> > To: basicstamps@egroups.com
> > Subject: [noparse][[/noparse]basicstamps] long numbers
> >
> >
> > Hi everyone,
> >
> > Can anyone tell me how to use long numbers.
> >
> > A word can only store a number upto 65535.
> >
> > I have designed a machine that requires 2 counters. One that counts
> > the number of operations it has completed in this run, which may have
> > upto 5 digits i.e. 99999 and the other that may have millions of
> > operations i.e. 99,999,999.
> > how do i get past the 65535? And how do I store the results in the
> > EEprom?
> >
> > The project is late and I'm getting hasle from the MD, so any help
> > gratefully recieved.
> >
> > Regards
> >
> > Jon
> >
> >
> >