set fp [open test.bin w]
fconfigure $fp -translation binary -encoding binary
puts -nonewline $fp [format binary s1 [expr 0x20]]
close $fp
when I open the file in binary editing mode (using UltraEdit), i am
seeing "20 00", it is appending 00 (NULL), don't know why...what else
needs to added to make it work properly
btw i am using tcl version 8.3.4
-Sanjeev
From http://tmml.sourceforge.net/doc/tcl/binary.html
"s
This form is the same as c except that it stores one or more 16-bit
integers in little-endian byte order in the output string. The low-order
16-bits of each integer are stored as a two-byte value at the cursor
position with the least significant byte stored first. For example,
binary format s3 {3 -3 258 1}
will return a string equivalent to \x03\x00\xfd\xff\x02\x01.
"
Emphasis "two-byte".
--
Les Cargill
Why do you need format? (Which does not work as written: it puts in the
file just "binary")
George
found the way replacing 's' with 'c' character works
set fp [open test.bin w]
fconfigure $fp -translation binary -encoding binary
puts -nonewline $fp [format binary c1 [expr 0x20]]
close $fp
>set fp [open test.bin w]
>fconfigure $fp -translation binary -encoding binary
>puts -nonewline $fp [format binary s1 [expr 0x20]]
I assume you mean [binary format s ..]
You asked it to write a 2 byte signed integer (aka short). Therefore
you got a file with two bytes in little-endian byte order.
If you want a single byte - use 'c'
--
Pat Thoyts http://www.patthoyts.tk/
To reply, rot13 the return address or read the X-Address header.
PGP fingerprint 2C 6E 98 07 2C 59 C8 97 10 CE 11 E6 04 E0 B9 DD