View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.misc
joeu2004 joeu2004 is offline
external usenet poster
 
Posts: 2,059
Default Precision As Displayed Has Failed Me--Help

On Jul 11, 10:02*am, "Niek Otten" wrote:
Just (very) curious:
How do you examine the internal binary representations
of Excel's data?


In its simplest form, I use the following function, dbl2bin(). The
actual implementation has some bells and whistles that complicate
things.


Function dbl2bin(arg) As String
Dim lng As Tlong2
Dim dbl As Tdouble
Dim lng1 As String, lng0 As String
Dim out1 As String, out0 As String

' LSet requires user-defined types
'
' With OnError, "dbl.val=arg" converts (&h7ffxNNNN,z)
' to (&h7ffyNNNN,z), where x=0-7, y=8-f and z0 if x=0,
' otherwise z=0; that is, everything except INF, which
' is (&h7ff00000,0). Without OnError, assignment causes
' error. CopyMemory avoids error on assignment; and it
' should avoid conversion. but CopyMemory might not be
' portable; and it might not be worth the trouble since
' we cannot find a way for "arg" to be any of the values
' (&h7ffxNNNN,z) as described above.

On Error Resume Next
dbl.val = arg
LSet lng = dbl

lng1 = Hex(lng.val(1)): len1 = Len(lng1)
out1 = "&h00000000": Mid(out1, 11 - len1, len1) = lng1

lng0 = Hex(lng.val(0)): len0 = Len(lng0)
out0 = "00000000": Mid(out0, 9 - len0, len0) = lng0

dbl2bin = out1 & "," & out0
End Function