Re: LZ: Re:Need algorithmic help!!!
[Prev][Next][Index][Thread]
At 04:48 PM 11/19/96 +0100, Dines Justesen wrote:
>Marty Williams wrote:
>>
>> I need some help understanding part of the link protocol for the TI-85. Any
>> help would be gratefully appreciated.
>>
>> I'll use the information in the Link-protocol Document as the reference for
>> my question.
>>
>> I am trying to understand how a real number variable is packet ed into the
>> message packet. In the doc the variable sent is Pi. As you look at the
>> actual bytes being transmitted, you can see the numbers for Pi. These
>> numbers are hex numbers and the check sum is calculated with the hex value.
>> How does this 3.145926d, get converted to 31 41 59 26h. And then when you
>> receive this, how is it converted back to a decimal value?
>The format of the floating point numbers used on the ti85 includes the
>digits written in BCD, which is what you see as a hex number.
>
>PI = 0000FC3141592659890000
>
>MHA has released a document expaning the format of the .85N files, and
>it axplains this too.
>
Ok, I see the BCD format in the number. But I don't understand how to do
the conversion. Can you help me with an algorithum that will take a number
and convert it into the Hex byte format needed to calculate the check-sum
and for tranmission. And then, to take it out of this format, back into a
decimal format.
<Cut-outs>
00 02 FC 12 30 00 00 00 00 00
What it means is this:
+--- <Range> (one byte)
|
| +--+--+--+--+--+--+--- <Number> (in BCD, 7 bytes)
| | | | | | | |
00 02 FC 12 30 00 00 00 00 00
| |
+--+--- <Exponent> (in hex, 2 bytes)
Thus, for the variable "Foo":
<Range> = FC
<Exponent> = 2
<Number> = 1.23
The value of the variable is given by:
Value = <Number>E[<Exponent> + (100)(<Range> - FC)]
So for "Foo":
Value = (1.23)E[2 - (100)(FC - FC)]
= (1.23)E(2)
= 123
----------------------------------------------------------------------------
---------------
The format of a real value is:
Offset Length Comment
====== ====== =======
00h 01h Byte: Sign. 00h -> Positive number; 80h -> Negative
number.
01h 01h Low order of 10^x value.
02h 01h High order of 10^x value.
The 10^x value is calculated using:
x=[01h]+256*([02h]-FCh)
03h 07h Hexa-decimal interpretion of value. The decimal point
lies between Low and High nibble of [03h].
The reason that the 10^x value seems so complicated is that it should handle
values between 10^999 <-> 10^-999.
The "value-part" may seem confusing, but I just didn't know how to say it.
A few examples will illustrate (and hopefully solve) the problem:
Storage
Value 00 01 02 03 04 05 06 07 08 09
=====================================
10 00 01 FC 10 00 00 00 00 00 00
Pi 00 00 FC 31 41 59 26 53 58 98
-Pi 80 00 FC 31 41 59 25 53 58 98
9.99E999 00 E7 FF 99 90 00 00 00 00 00
2.5E-35 00 DD FB 25 00 00 00 00 00 00
References: