Results 1 to 5 of 5

Thread: [RESOLVED] VB6 Convert Double to Binary String

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Resolved [RESOLVED] VB6 Convert Double to Binary String

    Can you please help me Convert Double to Binary String?

    for example, -1.75888576432121E+16 to Binary string.

    My code only can deal with Long type.

    Code:
    Public Function LongToBitString(theValue As Long) As String
    
    ' Function converts byte, integer, long to a bit string
    ' String length is equal to bit count of the passed variable
    
    Dim b As Integer, tValue As Long
    Dim mPO2lut(0 To 31) As Double ' 2^31 is a double not Long & used when wrapping shifts
    Const bitOn As String = "1"
    Const bitOff As String = "0"
    
    Const HighBitMask As Long = &H80000000
    Const bitLen As Long = 32
    
    Dim i As Integer
    
        mPO2lut(0) = 1#
        For i = 1 To 31
            mPO2lut(i) = mPO2lut(i - 1) * 2&
        Next i
    
        tValue = (theValue And Not HighBitMask)
        LongToBitString = String$(bitLen, bitOff)
        For b = 0 To bitLen - 2
            If ((tValue \ mPO2lut(b)) And 1) Then Mid$(LongToBitString, bitLen - b, 1) = bitOn
        Next b
        If (theValue And HighBitMask) Then Mid$(LongToBitString, 1, 1) = bitOn
    
    End Function
    Attach VB6 Data Types:
    Long (long integer) 4 bytes -2,147,483,648 to 2,147,483,647
    Single (single-precision floating-point) 4 bytes -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values. About 6 or 7 significant figures accuracy.
    Double (double-precision floating-point) 8 bytes -1.79769313486231E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values. About 15 or 16 significant figures accuracy.
    Currency (scaled integer) 8 bytes -922,337,203,685,477.5808 to 922,337,203,685,477.5807
    Decimal 14 bytes +/-79,228,162,514,264,337,593,543,950,335 with no decimal point; +/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest non-zero number is +/-0.0000000000000000000000000001
    Last edited by Jonney; Jul 23rd, 2014 at 08:18 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width