comp.lang.ada
 help / color / mirror / Atom feed
From: "stuart clark" <stuartlclark@hotmail.com>
Subject: Re: floating point to fixed point conversion
Date: 22 Feb 2006 03:01:08 -0800
Date: 2006-02-22T03:01:08-08:00	[thread overview]
Message-ID: <1140606068.242508.155830@g44g2000cwa.googlegroups.com> (raw)
In-Reply-To: <1140560157.376760.292570@g43g2000cwa.googlegroups.com>

Not sure if this is what you are after but an example from a real IDD,
where floats are represented as 16 bit signed integers, the 16th bit is
the sign bit.

Eg from a real life navigational computer IDD

magnetic heading = +/-180 degrees.
bits to use = 15, the 16th bit the sign bit

pass integers across an interface, which are then converted to floats
using a known scaling factor.

scaling factor = 180 / (2^15 ) = 0.005493....

we define the integer value of 1 = 0.005493.... and we call this value
the LSB.

>From basics where 15 bits can represent a max value of 2^15 -1 we now
have max value of 180 - LSB (iw 2^15 =180 and 1 =LSB)

therefore to send 180 - LSB across an interface what integer value do
you need = 180 / scaling factor = (180  - 0.005493..) / 0.005493 =
32767 (the old 2^15-1) = 0x7FFF

90 degrees = 90 / 0.005493 = 16383.5 = 0x3FFF

but note there is an accuracy loss as

0x3FFF * 0.005493 = 89.997

Thats hows its done in real life, hope it helps!

Stuart Clark




  parent reply	other threads:[~2006-02-22 11:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-21 22:15 floating point to fixed point conversion riya1012
2006-02-21 23:49 ` Jeffrey R. Carter
2006-02-21 23:51 ` Keith Thompson
2006-02-22  0:51   ` Keith Thompson
2006-02-22 11:01 ` stuart clark [this message]
2006-02-22 14:25 ` Peter Hermann
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox