求教各位高手。。这儿有道VB编程题:输入正整数N,求其对应的二进制数。。

谢谢了。。
2024年11月19日 19:37
有2个网友回答
网友(1):

十进制转二进制
Public Function DECtoBIN(Dec As Long) As String
DECtoBIN = ""
Do While Dec > 0
DECtoBIN = Dec Mod 2 & DECtoBIN
Dec = Dec \ 2
Loop
End Function

十进制转八进制:
VB自带函数:Oct(num)

十进制转十六进制:
VB自带函数:hex(num)

网友(2):

Public Function Dec2Bin(ByVal num As Long) As String
Do
Dec2Bin = num Mod 2 & Dec2Bin
num = num \ 2
Loop While num <> 0
End Function

private sub Form_Click()
dim n as long
n=inputbox("")
print Dec2Bin(n)
end sub