[[...]] [[... atoms ...]] [[... other pages ...]] % set hex 3A 3A % scan $hex %x decimal 1 % set decimal 58 '''Decimal to hex:''' format %4.4X $decimalNumber Notice that the ".4" part gives leading zeroes, and does '''not''' have to do with the fractional (right-of-the-point) part of the number. '''Character to hex''': format %4.4X [scan $c %c] Notice that "[[scan $c %c]]" only does what one wants with newer Tcl's, those since version 8.3.0+. ---- mfi: Can someone suggest a pure Tcl replacement for this command: proc format-hex-data data { set fd [open tp w] fconfgure $fd -translation binary -encoding binary puts -nonewline $fd $data close $fd set result [exec xxd tp] file delete tp return $result } ---- [RS]: Sure enough - the following proc returns the hexdump of a file, formatted as with xxd, as a string: proc file:open.hex {fn} { set f [open $fn r] fconfigure $f -translation binary set where 0 set res {} while {![eof $f]} { set data [read $f 16] if {![binary scan $data H* t] || $t==""} break regsub -all (....) $t {\1 } t2 set asc "" foreach i $t2 { scan $i %2x c if {$c>=32 && $c<=127} { append asc [format %c $c] } else { append asc "." } } lappend res [format "%7.7x: %-40s %s" $where $t2 $asc] incr where 16 } close $f join $res \n } But in your case, the detour over a file is not really necessary - maybe do the ''binary scan'' directly over the data, positioning @ $where? (More soon.) ----