Exact match. Not showing close matches.
PICList
Thread
'[PIC]:Re: Maths Problem'
2001\01\19@092520
by
o88591?Q?K=FCbek_Tony?=

Well as Tony Nixon suggested an fixed format is the way to go here.
I would suggest an 16.8 or if range is enough 8.8.
It's then very easy to scale this by using Nicolai's code generator.
For example for 16.8 (binary) to 6.2 ( fixed point with 2 digits after
decimalpoint ) you need to scale something like this:
16.8 / 256 is the integer part, but we also want 2 digit from the
decimal
part and hence we add * 100 and gets:
16.8 * 100 / 256 = 16.8 * 0.390625
Enter this in the code generator ( i.e constant 0.390625 )
input size 24 bits. And all the code you need will be generated.
Example ( using your value here ):
26.47 ( decimal ) would be in 16.8 format:
Integerpart > 26 = top two bytes = 0x001A in hexadecimal.
Decimal part > 47 * 2.56 = 120.32 ( this code could also be generated
by above code generator ), we cut the decimal part and have 120 left
which is
0x78 in hex.
We now have the original value in 16.8 format as:
0x001A78 ( which btw is 6776 decimal if treated as 24 bit value )
Run this though the code generated above ( 0x001A78 * 0.390625 )
and you will have:
0x000A56 or 0x000A57 ( depending how you handle rounding )
which is 2646 or 2647 in decimal. Now as we have decided to have an
'fixed' point with two decimals you already know where to set the
decimal
point. take the 24 bit value run it through the 24>ascii routine found
on the
piclist site, place the decimal point two digits from the last and there
you go.
/Tony
Tony Kübek, Flintab AB
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²
Email: spam_OUTtony.kubekTakeThisOuTflintab.com
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²

http://www.piclist.com hint: The PICList is archived three different
ways. See http://www.piclist.com/#archives for details.
More... (looser matching)
 Last day of these posts
 In 2001
, 2002 only
 Today
 New search...