How can I see the actual binary content of a VB6 Double variable?

419 views Asked by At

I have hunted about quite a bit but can't find a way to get at the Hexadecimal or Binary representation of the content of a Double variable in VB6. (Are Double variables held in IEEE754 format?)

The provided Hex(x) function is no good because it integerizes its input first. So if I want to see the exact bit pattern produced by Atn(1), Hex(Atn(1)) does NOT produce it.

I'm trying to build a mathematical function containing If clauses. I want to be able to see that the values returned on either side of these boundaries are, as closely as possible, in line.

Any suggestions?

1

There are 1 answers

3
Jim Mack On

Yes, VB6 uses standard IEEE format for Double. One way to get what you want without resorting to memcpy() tricks is to use two UDTs. The first would contain one Double, the second a static array of 8 Byte. LSet the one containing the Double into the one containing the Byte array. Then you can examine each Byte from the Double one by one.

If you need to see code let us know.

[edit]

At the module level:

Private byte_result() As Byte

Private Type double_t
    dbl As Double
End Type

Private Type bytes_t
    byts(1 To 8) As Byte
End Type

Then:

Function DoubleToBytes (aDouble As Double) As Byte()
   Dim d As double_t
   Dim b As bytes_t
   d.dbl = aDouble
   LSet b = d
   DoubleToBytes = b.byts
End Function

To use it:

Dim Indx As Long

byte_result = DoubleToBytes(12345.6789#)

For Indx = 1 To 8
   Debug.Print Hex$(byte_result(Indx)),
Next

This is air code but it should give you the idea.