Function tob(ByVal n As Long) As String
Dim a() As String, temp As Long, i As Long
temp = Int(Log(n * 15 + 15) / Log(16))
n = n - 1 - (16 ^ temp - 16) / 15
temp = 5 * temp - 1
ReDim a(1 To temp)
For i = temp To 1 Step -1
If i Mod 5 = 0 Then
a(i) = ","
Else
a(i) = n Mod 2
n = n \ 2
End If
Next
tob = Join(a, "")
End Function
Private Sub Command1_Click() '随机测试
Dim x As Long
Randomize
x = Int(Rnd * 100000)
MsgBox x & " --->" & tob(x)
End Sub
Function tob(ByVal n As Long) As String
Dim a() As String, i As Long, temp As Long
n = n - 1
temp = 5 * (Int(Log(n) / Log(2)) \ 4 + 1) - 1
ReDim a(1 To temp)
For i = temp To 1 Step -1
If i Mod 5 = 0 Then
a(i) = ","
Else
a(i) = n Mod 2
n = n \ 2
End If
Next
tob = Join(a, "")
Erase a
End Function
Private Sub Command1_Click()
Dim i As Integer
For i = 1 To 100
Debug.Print i; ":"; tob(i)
Next
End Sub
Function tob(ByVal n As Long) As String
Dim a() As String, i As Long, temp As Long
temp = Int(Log(n + 1) / Log(2))
n = n + 1 - 2 ^ (temp)
ReDim a(1 To temp)
For i = temp To 1 Step -1
a(i) = n Mod 2
n = n \ 2
Next
tob = Join(a, "")
Erase a
End Function