【发布时间】:2014-12-10 17:31:24
【问题描述】:
proc str2hex { string } {
set str [binary scan $string H* hex]
puts $hex
regsub -all (..) $hex {\1 } t1
set res [format "%s" $t1 ]
return $res
proc hex2str { $hex } {
puts "HIIHI"
foreach c [split $$hex ""] {
if {![string is xdigit $c]} {
return "#invalid $$hex"
}
}
set hexa [binary format H* $$hex]
return $hexa
}
}
以上是将字符串转换为十六进制的简单代码。我制作了嵌套的proc,其中将“set str [binary scan $string H* hex]”脚本中的十六进制作为输入,以便将十六进制重新转换为字符串。请帮助我。
【问题讨论】: