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 |