A long time ago i had to deal with 2 byte floating point numbers in VB6.

Now I have to convert my old project to Xojo.

Example:

2bytes hex = desimal value

&h1400 = 1

&hB001 = 1

&h1C00 = -1

&hB801 = -1

&h7640 = 100

&hB064 = 100

&h7634= 99.2

&h6544= 42.1

I have my VB6 code from way back in time casting long to a single loosing bits and back.

How to make this work in Xojo ?

[code]Public Type Sng

dta As Single

End Type

Public Type Lng

dta As Long

End Type

Public Function IEEE_To_Normal(ByVal Ieee As String) As Single

Dim vLng As Lng

Dim vSng As Sng

vLng.dta = Ieee

LSet vSng = vLng

IEEE_To_Normal = vSng.dta

End Function

Public Function Normal_To_Ieee(ByVal Normal As Single) As String

Dim vLng As Lng

Dim vSng As Sng

vSng.dta = Normal

LSet vLng = vSng

Normal_To_Ieee = Hex$(vLng.dta)

End Function[/code]

The explanation using low level exponet and mantissa calculation:

The 16 bits string is characterized by three components,

an exponent, a sign and a significant. Its numerical value is the signed product of its significant and

two raised to the power of its exponent.

2 Bytes Floating Point Format where:

e 4 bits exponent. Any integer between 0 and 15

s 1 bit sign (0 = positive, 1 = negative)

f 11 bits fractional significant with an implied binary point

and the format: 0.b0b1…b10

The numerical value of a floating point string can be calculated as:

Numerical Value = (-1)s 2e (0.b0b1…b10)

The numerical value of the nth bit (bn) in the significant field (n from 0 to 10) is:

Significant Value(bn) = 2-(n + 1)

A number is zero when all bits of the fractional significant are 0.