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
11 个解决方案
#1
不错
xuexi
xuexi
#2
看看..
#3
想法比较巧妙,但是以前在哪见过几位高人讨论,说这样速度或者效率会受影响,不过自己没试过。
#4
相同方法,附上二进制转八进制和十六进制代码
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
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
#5
看看.. bu不错
#6
十六进制转二进制想法是不错,但是有BUG,不知试过没有,0-9这样的十六进制是可以转的,但是A——F就不行了
不信你试试看
不信你试试看
#7
我不知楼上的让我试什么,我记得好像试过才发的,是不是你弄错了
#8
感觉满巧妙的
#9
学习学习
#10
进制转换,学学
#11
不错
谢谢!
谢谢!
#1
不错
xuexi
xuexi
#2
看看..
#3
想法比较巧妙,但是以前在哪见过几位高人讨论,说这样速度或者效率会受影响,不过自己没试过。
#4
相同方法,附上二进制转八进制和十六进制代码
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
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
#5
看看.. bu不错
#6
十六进制转二进制想法是不错,但是有BUG,不知试过没有,0-9这样的十六进制是可以转的,但是A——F就不行了
不信你试试看
不信你试试看
#7
我不知楼上的让我试什么,我记得好像试过才发的,是不是你弄错了
#8
感觉满巧妙的
#9
学习学习
#10
进制转换,学学
#11
不错
谢谢!
谢谢!