TA的每日心情 | 慵懒 2018-2-11 09:23 |
---|
签到天数: 8 天 [LV.3]偶尔看看II
|
昨天看到两个人在问vb十进制转十六进制的算法,原因是在写注册机的使用用HEX函数溢出,我帮着简单写了个
Private Sub Text1_Change()
s1 = Val(Text1)
Do
temp = s1 - Int(s1 / 16) * 16
s1 = Int(s1 / 16)
If temp < 10 Then TEMP1 = CStr(temp)
If temp = 10 Then TEMP1 = "A"
If temp = 11 Then TEMP1 = "B"
If temp = 12 Then TEMP1 = "C"
If temp = 13 Then TEMP1 = "D"
If temp = 14 Then TEMP1 = "E"
If temp = 15 Then TEMP1 = "F"
S2 = TEMP1 & S2
Loop While s1 > 0
Text2 = S2
End Sub
十六进制转十进制(没测试)
For i = len(text1) To 1 Step -1
temp=Mid(text1, i, 1)
if temp="A" THEN TEMP1=10
if temp="B" THEN TEMP1=11
if temp="C" THEN TEMP1=12
if temp="D" THEN TEMP1=13
if temp="E" THEN TEMP1=14
if temp="F" THEN TEMP1=15
IF ISNUMBERIC(TEMP) TEHN TEMP1=VAL(TEMP)
TEMP2 = TEMP2 + TEMP1*16 ^ (Len(TEXT1) - i)
End If
Next i
TEXT2=TEMP2 |
|