I had occasion to write a 5-byte number to a binary file. The only way I could think of to do it was to "format" the number into a 64-bit (W) number, "scan" it into a HEX string, parse the string 1 byte at a time, and write out the 5 individual (least significant) bytes:
Is there a better way?
Bob Rashkin
rrashkin@csc.com
Code:
set t4 [binary format W $newt]
binary scan $t4 H16 hxt
for {set i 6} {$i<16} {incr i 2} {
set i2 [expr {$i+1}]
set bt [string range $hxt $i $i2]
scan $bt %x bt2
puts -nonewline $fid [binary format c $bt2]
}
Bob Rashkin
rrashkin@csc.com