by Jim Tran Phelps (1 Submission)
Category: Math/Dates
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Sat 9th June 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Convert a long to a Binary string of "10101010101......"
API Declarations
Debug.? ConvLongToBinaryStr(15)
Returns: 1111
Notes:
Be creative and I am sure without much change you can take this code to handle any numeric base. Please feel free to improve the code and please let me know of any changes you would like to make to it. I love to learn how to write better code.
Dim lWorkNumber As Long
Dim nMod As Integer
Dim sRet As String
nMod = pi_ConvertMe Mod 2
lWorkNumber = (pi_ConvertMe - 0.5) / 2
If (pi_ConvertMe > 0) Then
If lWorkNumber > 0 Then
ConvLongToBinaryStr = ConvLongToBinaryStr(lWorkNumber) + CStr(nMod)
Else
ConvLongToBinaryStr = CStr(nMod)
End If
Else
ConvLongToBinaryStr = "0"
End If
End Function