//字符串转换为16进制
string ls_hex = '',hex =''
char lch_hex[0 to 15] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}
int li_d,i
character ac_d
If IsNull(astr) Then
SetNull(ls_hex)
Return ls_hex
End If
for i=1 to len(astr)
ac_d = mid(astr,i,1)
li_d = asc(ac_d)
hex = ''
Do
hex = lch_hex[mod(li_d, 16)] + hex //mod 取余数
li_d /= 16
Loop Until li_d= 0
if len(hex) = 1 then hex = '0' + hex
ls_hex = ls_hex + hex
next
Return ls_hex
//16进制转换为字符串
string ls_str = ''
char lch_hex[0 to 15] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}
int li_d,i,m,k,l
character ac_d
If IsNull(as_hex) Then
SetNull(as_hex)
Return as_hex
End If
k = len(as_hex)/2
for i=0 to k -1
ac_d = mid(as_hex,i*2 + 1,1)
for m = 0 to 15
if lch_hex[m] = ac_d then exit
next
ac_d = mid(as_hex,i*2 +2,1)
for l = 0 to 15
if lch_hex[l] = ac_d then exit
next
li_d = m * 16 + l
ac_d = Char(li_d)
ls_str = ls_str + ac_d
next
Return ls_str
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/yuehaiyang/article/details/2726183
标签:十六进制,ac,16,hex,li,PB,ls,互转,lch From: https://www.cnblogs.com/fengzi1001/p/18326142