# 一个八进制和十六进制转二进制的奇妙方法

z_wenqian 2008-01-08 02:48:29

Public Function OctToBin(ByVal sOct As String) As String
Const s1 = "0001011100", s2 = "01253764"
Dim i As Integer, sBin As String
For i = 1 To Len(sOct)
sBin = sBin & Mid(s1, InStr(1, s2, Mid(sOct, i, 1)), 3)
Next i
OctToBin = sBin
End Function

Public Function HexToBin(ByVal sHex As String) As String
Const s1 = "0000101001101111000", s2 = "0125A4936DB7FEC8"
Dim i As Integer, sBin As String
sHex = UCase(sHex)
For i = 1 To Len(sHex)
sBin = sBin & Mid(s1, InStr(1, s2, Mid(sHex, i, 1)), 4)
Next i
HexToBin = sBin
End Function
...全文
6163 点赞 收藏 11

11 条回复

6742 2012-02-18

skdyu 2011-09-26

wangxin5576 2009-08-17

pusiyu 2009-08-09

z_wenqian 2009-04-20

lancelotaerin 2009-03-29

zcfhero 2008-03-26

z_wenqian 2008-01-09

Public Function BinToOct(ByVal sBin As String) As String
Const s1 = "0001011100", s2 = "01253764"
Dim i As Integer, sOCt As String
sBin = String(2 - (Len(sBin) - 1) Mod 3, "0") & sBin
For i = 1 To Len(sBin) Step 3
sOCt = sOCt & Mid(s2, InStr(1, s1, Mid(sBin, i, 3)), 1)
Next i
BinToOct = sOCt
End Function

Public Function BinToHex(ByVal sBin As String) As String
Const s1 = "0000101001101111000", s2 = "0125A4936DB7FEC8"
Dim i As Integer, sHex As String
sBin = String(3 - (Len(sBin) - 1) Mod 4, "0") & sBin
For i = 1 To Len(sBin) Step 4
sHex = sHex & Mid(s2, InStr(1, s1, Mid(sBin, i, 4)), 1)
Next i
BinToHex = sHex
End Function

tingting1123 2008-01-08

awperpvip 2008-01-08

xuexi

VB基础类

7476

VB 基础类

2008-01-08 02:48