Version 10 of hexadecimal conversions

Updated 2002-04-23 09:31:09

[...]

[... 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

}