CodeItBetter Programming Another VB Programming Blog

How to convert Decimal Number to Binary Number

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'Math - How to convert Decimal Number to Binary Number

Public Function Dec2Bin(myNum As Variant) As String
    Dim loopcounter As Integer
    If myNum >= 2 ^ 31 Then
        Dec2Bin = "Number 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
 
Private Sub Main()
    MsgBox Dec2Bin(63923)
End Sub

Related posts:

  1. How to convert Binary Number to Decimal Number
  2. How to Convert from decimal to binary
  3. How to Conversion (Binary, Hexa Decimal, Octal, Decimal)
  4. How to Convert Binary to Decimal
  5. How to Convert a decimal number into a Roman number?
  6. How to convert Hexadecimal number to Decimal number
  7. How to convert Decimal Number to Hexadecimal Number
  8. How to convert Octal to Decimal number
  9. How to Convert Decimal to Hexadecimal
  10. How to Convert Binary to Octal

Filed under: Math Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.