Please help me. What is a code how to convert dotted decimal to binary and vice versa. and small explanation

Member Avatar
Dim DecimalNumber As Double = 85.78

       'an easy way is to use the BitConverter Class
       Dim DecimalBytes() As Byte = BitConverter.GetBytes(CDbl(DecimalNumber))
       'this will now contain 16 bytes

       'another way is to use the BinaryWriter
       Dim mStream As New System.IO.MemoryStream
       Dim bWriter As New System.IO.BinaryWriter(mStream)

       bWriter.Write(CDbl(DecimalNumber))

       Dim TheOtherDecimalBytes() As Byte = mStream.ToArray
       'This will contain the 16 bytes.  The same as the Decimal Bytes()


       'To Convert the bytes back to decimal
       Dim DecimalFromBitConverter As Double = BitConverter.ToDouble(DecimalBytes, 0)


        'Using the Binary Reader
        mStream = New MemoryStream(TheOtherDecimalBytes)
        Dim bReader As New BinaryReader(mStream)

        Dim DecimalFromBinaryReader As Double = bReader.ReadDouble

Just make sure to mark the thread as solved when when your situation is solved.


And I just noticed the VB6 in your post.

Don't post VB6 Questions here.

I have just wasted time posting this. It will not help you. You would be better off finding information on VB6 in the Cobol or Fortran forums.