Forum Discussion
adack
Nimbostratus
That's what worked for me:
proc hex2ascii {sHex} {
# latin-1 supplement, unicode u+0000 - u+00ff
set iByte 0
# check if string begins with '0x'
if { [scan $sHex {0x%s} sHex] > 0} {
# loop each character
foreach sChar [ split [binary format H* $sHex] ""] {
# convert to decimal
scan $sChar %c iChar
if {$iChar < 0x80} {
# standard ascii
append sAscii $sChar
} elseif {$iChar > 0xc2} {
set iByte [expr ({$iChar} - 0xc2) * 0x40]
} elseif {$iChar < 0xc2} {
# convert to ascii
append sAscii "[format %c [expr {$iByte} + {$iChar}]]"
set iByte 0
}
}
return $sAscii
} else {
return $sHex
}
}
Calling the function with the following attribute will return ASCII
[call hex2ascii 0x434e3d....]
Hope this helps.
CA_Valli
Oct 19, 2021MVP
Used this today for the same purpose, it's working.
[encoding] TCL commands seem not to be available in iRule (tested in v13-14)