Results 1 to 3 of 3

Thread: Decimal to binary

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    7
    just ewondering if there is a simple way of converting a decimal number to its binary equivalent

  2. #2
    Matthew Gates
    Guest
    Try this:


    Code:
    Public Function dec2bin(mynum As Variant) As String
        Dim loopcounter As Integer
        If mynum >= 2 ^ 31 Then
            dec2bin = "Too big"
            Exit Function
        End If
        Do
            If (mynum And 2 ^ loopcounter) = 2 ^ loopcounter Then
                dec2bin = "1" & dec2bin
            Else
                dec2bin = "0" & dec2bin
            End If
            loopcounter = loopcounter + 1
        Loop Until 2 ^ loopcounter > mynum
    End Function

  3. #3
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530

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