VB Function — decimal to binary

Edited by Worren



Function Bin(strINT As String)

    Dim strBIN As String
    Dim i As Long, j As Long, L As Long

    L = Val(strINT)

    If L < 1 Then Exit Function

    strBIN = \"\"
    For i = (Log(L) / Log(2)) To 0 Step (-1)
        If L And (2 ^ i) Then
            strBIN = strBIN & \"1\"
        Else
            strBIN = strBIN & \"0\"
        End If
    Next
    
    If Left(strBIN, 1) = \"0\" Then strBIN = Right(strBIN, Len(strBIN) - 1)
    
    Bin = strBIN

End Function



Share your vote!


Do you like this post?
  • Fascinated
  • Happy
  • Sad
  • Angry
  • Bored
  • Afraid

Leave a Reply

Your email address will not be published. Required fields are marked *


Please help to input verification code