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.
Attach VB6 Data Types: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
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




Reply With Quote
