fuzzy math
Archiver
Posts: 46,084
Hi all,
I encountered some fuzzy math when I ran a program which composed of
the following lines.
jhday VAR byte
jday VAR byte
Main:
DEBUG Home
jday = jhday * 100
DEBUG DEC jhday, "; ", DEC jday
GOTO Main
END
When jhday = 3, i get 44 for jday. Why is that?
Any help would be appreciated. I was wondering how I can address bits
and nibbles from a byte array. I found out that byte_array
(index).lownib is a syntax error.
Thanks,
RP
I encountered some fuzzy math when I ran a program which composed of
the following lines.
jhday VAR byte
jday VAR byte
Main:
DEBUG Home
jday = jhday * 100
DEBUG DEC jhday, "; ", DEC jday
GOTO Main
END
When jhday = 3, i get 44 for jday. Why is that?
Any help would be appreciated. I was wondering how I can address bits
and nibbles from a byte array. I found out that byte_array
(index).lownib is a syntax error.
Thanks,
RP
Comments
1-256, the value you are trying to store is 300... 300-256 = 44. The
basicstamp is "wrapping" the value, it fills up the byte once then goes
around again to 44. change your "jday" variable to "jday VAR word".
Robert Staph, W3RCS
The Center for Advanced Technologies
Original Message
From: <rpsu279@y...>
To: <basicstamps@yahoogroups.com>
Sent: Friday, November 23, 2001 2:54 PM
Subject: [noparse][[/noparse]basicstamps] fuzzy math
> Hi all,
> I encountered some fuzzy math when I ran a program which composed of
> the following lines.
>
> jhday VAR byte
> jday VAR byte
>
>
>
> Main:
> DEBUG Home
> jday = jhday * 100
> DEBUG DEC jhday, "; ", DEC jday
> GOTO Main
> END
>
> When jhday = 3, i get 44 for jday. Why is that?
>
> Any help would be appreciated. I was wondering how I can address bits
> and nibbles from a byte array. I found out that byte_array
> (index).lownib is a syntax error.
>
> Thanks,
> RP
>
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
Sid
>and nibbles from a byte array. I found out that byte_array
>(index).lownib is a syntax error.
byte_array.nib0(index) will reference nibs.
byte_array.bit0(index) will reference bits
byte_array(0) is the same variable as byte_array
example with alias names:
byte_array var byte(8) ' array of 8 bytes
bat var byte_array ' alias for the 0th byte
' e.g., bat(7) is the last byte of 8
gnat var bat.nib0 ' alias for 0th nibble
' e.g., gnat(15) is the last nib of 16
bitty var bat.bit0 ' alias for 0th nibble
' e.g., bitty(63) for the last bit of 64
-- Tracy
The trick is that you are using bytes. These top out at 255. So:
jday = jhday * 100 ' 3*100 = 300 but 300>255 so the result is 44
(300-256)
Try using a word to store jday!
Al Williams
AWC
* 8 channels of PWM
http://www.al-williams.com/awce/pak5.htm
>
Original Message
> From: rpsu279@y... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=MbELUJ8IaR6TxLlzwkyvyCmMyTKKJgbpxTyHwzobUoCp1GQvdNZaAGLq9FWfmKr4we1Blh5KGwxsze5H]rpsu279@y...[/url
> Sent: Friday, November 23, 2001 1:55 PM
> To: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] fuzzy math
>
>
> Hi all,
> I encountered some fuzzy math when I ran a program which composed of
> the following lines.
>
> jhday VAR byte
> jday VAR byte
>
>
>
> Main:
> DEBUG Home
> jday = jhday * 100
> DEBUG DEC jhday, "; ", DEC jday
> GOTO Main
> END
>
> When jhday = 3, i get 44 for jday. Why is that?
>
> Any help would be appreciated. I was wondering how I can address bits
> and nibbles from a byte array. I found out that byte_array
> (index).lownib is a syntax error.
>
> Thanks,
> RP
>
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the
> Subject and Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>