Jumat, 11 November 2011

Convert a Decimal Number to Binary

Private Function CBin(Number As Integer) As String
Dim Temp As Variant
Temp = 1 'Can't fouble nothing
Do Until Temp > Number 'sets starting point for Len
    Temp = Temp * 2
Loop
Do Until Temp < 1
    If Number >= Temp Then
       CBin = CBin + "1"
       Number = Number - Temp
    Else
        CBin = CBin + "0"
    End If
    Temp = Temp / 2
Loop 'Loop until string is complete
CBin = CStr(Val(CBin))
End Function

Tidak ada komentar:

Posting Komentar