# Re: 请问如何转2进位？

Posted by Honey on July 13, 1999 at 12:35:59:

In Reply to: 请问如何转2进位？ posted by 飞云 on July 13, 1999 at 10:10:08:

: 假设有一数字 5
: 我要如何以最快的速度转成 101？
: 谢谢
在表单中加入Command1 Text1 Text2
Text1中输入十进位整数

Option Explicit

Private Sub Command1_Click()
Text2.Text = ch2bit(Text1.Text)
End Sub

Public Function ch2bit(s As String) As String
Dim i As Long, h As Long
Dim d, u
h = CLng(s)
i = 0
Do While 2 ^ i <= h
u = 2 ^ i
If u And h Then
ch2bit = "1" & ch2bit
Else
ch2bit = "0" & ch2bit
End If
i = i + 1
Loop
End Function

Follow Ups:

- Re: 请问如何转2进位？ 飞云 15:59:02 7/13/99 (0)