VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 十进制转二进制的函数
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:14535, 日期:2000-11-10
Decimal to Binary

A quick and easy function to return the binary value for a number, without any preceding "0"s. This function returns a string with the binary number.

Public Function dec2bin(mynum As Variant) As String
Dim loopcounter As Integer
If mynum >= 2 ^ 31 Then
dec2bin = "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