由于ttl语言中不支持十六进制和十进制的互相转换,这里采用脚本的方式实现。这里不需要连接服务器,本地也可实现
bat脚本内容
"C:\Program Files (x86)\teraterm5\ttpmacro.exe" "%~dp0dec2hex.ttl" 121 1424
exit
ttl内容 ,这里相当于定义了两个子程序
:dec2hex
;;十进制转十六进制
decnum=params[2]
;messagebox params[2] 'params[2]'
hexnum=''
str2int num decnum
;messagebox num 'int'
while num>0
a=num%16
if a<10 then
int2str aint a
strconcat hexnum aint
elseif a=10 then
strconcat hexnum 'a'
elseif a=11 then
strconcat hexnum 'b'
elseif a=12 then
strconcat hexnum 'c'
elseif a=13 then
strconcat hexnum 'd'
elseif a=14 then
strconcat hexnum 'e'
elseif a=15 then
strconcat hexnum 'f'
endif
num=num/16
endwhile
;messagebox hexnum 'hexnum'
strlen hexnum
len_hex=result
;messagebox len_hex 'len_hex'
hexstr=''
for i 1 len_hex
strcopy hexnum len_hex+1-i 1 substr
strconcat hexstr substr
next
sprintf2 hexstr1 'hex(%s)' hexstr
sprintf2 hexstrtitle 'dec(%s)=' params[2]
messagebox hexstr1 hexstrtitle
return
:hex2dec
;十六进制转十进制
hexstr2=params[3]
;messagebox params[3] 'params[3]'
strlen hexstr2
len_hex2=result
dec2=0
for i 1 len_hex2
strcopy hexstr2 len_hex2+1-i 1 ss
;;strmatch和数字做比较
strmatch ss '[0-9]'
if result=1 then
str2int s2 ss
elseif result=0 then
;;strcompare是比字符串大小的,result结果有三个:-1(ss比'a'小),=(ss和'a'一样),1(ss比'a'大)
strcompare ss 'a'
if result=0 then
s2=10
else
strcompare ss 'b'
if result=0 then
s2=11
else
strcompare ss 'c'
if result=0 then
s2=12
else
strcompare ss 'd'
if result=0 then
s2=13
else
strcompare ss 'e'
if result=0 then
s2=14
else
strcompare ss 'f'
if result=0 then
s2=15
endif
endif
endif
endif
endif
endif
endif
if i=1 then
sum=1
elseif i>1 then
sum=1
for j 1 i-1
sum=sum*16
next
endif
;messagebox s2 's2'
;messagebox sum 'mi'
dec2=s2*sum+dec2
next
sprintf2 decstr1 'dec(%d)' dec2
sprintf2 decstitle 'hex(%s)=' params[3]
messagebox decstr1 decstitle
return