求二进制转十六进制VB代码!!急急急急急
发布网友
发布时间:2024-05-08 03:35
我来回答
共2个回答
热心网友
时间:2024-11-22 20:41
Private Function Two16(ByVal X As String) As String '把二进制数转化为十六进制数
Do While Len(X) Mod 4 <> 0
X = "0" + X
Loop
Do While Len(X) > 0
Select Case Right(X, 4)
Case "0000"
Two16 = "0" + Two16
Case "0001"
Two16 = "1" + Two16
Case "0010"
Two16 = "2" + Two16
Case "0011"
Two16 = "3" + Two16
Case "0100"
Two16 = "4" + Two16
Case "0101"
Two16 = "5" + Two16
Case "0110"
Two16 = "6" + Two16
Case "0111"
Two16 = "7" + Two16
Case "1000"
Two16 = "8" + Two16
Case "1001"
Two16 = "9" + Two16
Case "1010"
Two16 = "A" + Two16
Case "1011"
Two16 = "B" + Two16
Case "1100"
Two16 = "C" + Two16
Case "1101"
Two16 = "D" + Two16
Case "1110"
Two16 = "E" + Two16
Case "1111"
Two16 = "F" + Two16
End Select
X = Left(X, Len(X) - 4)
Loop
End Function
热心网友
时间:2024-11-22 20:42
直接调用就行,如print
two16("01000001")
private
function
two16(byval
x
as
string)
as
string
'把二进制数转化为十六进制数
do
while
len(x)
mod
4
<>
0
x
=
"0"
+
x
loop
do
while
len(x)
>
0
select
case
right(x,
4)
case
"0000"
two16
=
"0"
+
two16
case
"0001"
two16
=
"1"
+
two16
case
"0010"
two16
=
"2"
+
two16
case
"0011"
two16
=
"3"
+
two16
case
"0100"
two16
=
"4"
+
two16
case
"0101"
two16
=
"5"
+
two16
case
"0110"
two16
=
"6"
+
two16
case
"0111"
two16
=
"7"
+
two16
case
"1000"
two16
=
"8"
+
two16
case
"1001"
two16
=
"9"
+
two16
case
"1010"
two16
=
"a"
+
two16
case
"1011"
two16
=
"b"
+
two16
case
"1100"
two16
=
"c"
+
two16
case
"1101"
two16
=
"d"
+
two16
case
"1110"
two16
=
"e"
+
two16
case
"1111"
two16
=
"f"
+
two16
end
select
x
=
left(x,
len(x)
-
4)
loop
end
function