打开APP
未登录
开通VIP,畅享免费电子书等14项超值服
开通VIP
首页
好书
留言交流
下载APP
联系客服
进制转换的代码
zele
>《VB》
2011.02.12
关注
'10 to 16
Public Function Dec2Hex$(ByVal lngS&)
Dim t$
t = Hex(lngS)
If (Len(t) And 1) = 1 Then t = "0" & t
Dec2Hex = t
End Function
'16 to 2
Public Function Hex2Bin$(ByVal strHex$)
Const hS As String = "0124937FEDA5B6C8"
Const bhS As String = "0000100111101011000"
Dim i%
For i = 1 To Len(strHex)
Hex2Bin = Hex2Bin & Mid$(bhS, InStr(1, hS, Mid$(strHex, i, 1), vbTextCompare), 4)
Next
End Function
'10 to 2
Public Function Dec2Bin$(ByVal lngS&)
Dec2Bin = Hex2Bin(Dec2Hex(lngS))
End Function
'10 to 8
Public Function Dec2Oct$(ByVal lngS&)
Dec2Oct = Oct(lngS)
End Function
'8 to 2
Public Function Oct2Bin$(ByVal strOct$)
Const oS As String = "01253764"
Const boS As String = "0001011100"
Dim i%
For i = 1 To Len(strOct)
Oct2Bin = Oct2Bin & Mid$(boS, InStr(1, oS, Mid$(strOct, i, 1), vbTextCompare), 3)
Next
End Function
'2 to 8
Public Function Bin2Oct$(ByVal strBin$)
Const oS As String = "01253764"
Const boS As String = "0001011100"
Dim i%, t$
strBin = Right$("00" & strBin, ((Len(strBin) + 2) \ 3) * 3)
For i = 1 To Len(strBin) Step 3
t = t & Mid$(oS, InStr(1, boS, Mid$(strBin, i, 4), vbTextCompare), 1)
Next
Bin2Oct = t
End Function
'2 to 16
Public Function Bin2Hex$(ByVal strBin$)
Const hS As String = "0124937FEDA5B6C8"
Const bhS As String = "0000100111101011000"
Dim i%, t$
strBin = Right$("000" & strBin, ((Len(strBin) + 3) \ 4) * 4)
For i = 1 To Len(strBin) Step 4
t = t & Mid$(hS, InStr(1, bhS, Mid$(strBin, i, 4), vbTextCompare), 1)
Next
If (Len(t) And 1) = 1 Then t = "0" & t
Bin2Hex = t
End Function
'2 to 10
Public Function Bin2Dec&(ByVal strBin$)
Bin2Dec = CLng("&H0" & Bin2Hex(strBin))
End Function
'16 to 10
Public Function Hex2Dec&(ByVal strHex$)
Hex2Dec = CLng("&H0" & strHex)
End Function
'16 to 8
Public Function Hex2Oct$(ByVal strHex$)
Hex2Oct = Bin2Oct(Hex2Bin(strHex))
End Function
'8 to 16
Public Function Oct2Hex$(ByVal strOct$)
Oct2Hex = Bin2Hex(Oct2Bin(strOct))
End Function
'8 to 10
Public Function Oct2Dec&(ByVal strOct$)
Oct2Dec = Hex2Dec(Oct2Hex(strOct))
End Function
复制代码
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报
。
打开APP,阅读全文并永久保存
查看更多类似文章
猜你喜欢
类似文章
【热】
打开小程序,算一算2024你的财运
Visual Basic编程疑难问题解
VB实用代码,收藏!!
如何通过VB获取网卡地址
VB或VBA代码转HTML的加载宏
想出一种VB也能生成汇编的方法,有心者看能不能再发扬光大了
标题栏
更多类似文章 >>
生活服务
热点新闻
留言交流
回顶部
联系我们
分享
收藏
点击这里,查看已保存的文章
导长图
关注
一键复制
下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!
联系客服
微信登录中...
请勿关闭此页面
先别划走!
送你5元优惠券,购买VIP限时立减!
5
元
优惠券
优惠券还有
10:00
过期
马上使用
×