Function?btoh(m?As?String)?As?String?' realizes the conversion of 4-digit binary to 1-digit hexadecimal
Dim?s?As?Integer,? i?As?Integer
Dim?str?As?String
str?=?"0123456789ABCDEF"?' Hexadecimal string, F represents decimal 15
s?=?0
For?i?=?1?To?4
s?=?s?*?2?+?Val(Mid( m,?i,?1))?'4-digit binary to decimal conversion
Next?i
btoh?=?Mid(str,?s?+?1, ?1)?'-----Get a corresponding number from the hexadecimal string
End?Function
Private?Sub?Command1_Click()
< p>Dim?ans?As?String,?s?As?String,?ch?As?String,?ret?As?StringDim?i?As?Integer,?ascl?As? Integer,?n?As?Integer
s?=?Text1.Text
ans?=?""
For?i?=?1? To?Len(s)
ch?=?Mid(s,?i,?1)?'Take a character from the string
ascl?=?Asc(ch )?'Convert the character into its ascii code
ret?=?""
For?m?=?1?To?8
n ?=?(ascl?+?1)?Mod?2?'The remainder of asc1+1 and 2 is guaranteed to be bitwise inverted
ret?=?n?&?ret?'generated after inversion The binary string, if asc1 does not add 1, you can get the original code
ascl?=?ascl?\?2?'-----For the remainder method of Euclidean division, you can look at the decimal system How to convert to binary
Next?m
ret?=?Mid(ret,?4,?5)?+?Mid(ret,?1,?3)?' Rotate left by three digits
s1?=?btoh(Mid(ret,?1,?4))?'Convert the first 4 digits of the binary number to hexadecimal
s2?= ?btoh(Mid(ret,?5,?4))?'Convert the last 4 digits of the binary number to hexadecimal
ans?=?ans?&?s1?&?s2
< p>Next?iText2.Text?=?ans
End?Sub
For a high school student, this question is a bit difficult. It involves There are too many base conversions and it is not easy to understand them.