Re: binary scan and signed characters



On 29 août, 23:15, Arjen Markus <arjen.mar...@xxxxxxxxxx> wrote:
Hello,

I stumbled upon the following:

I have a PGM file (one of the picture formats that Tk supports via the
image command) that I want
to read via Tcl (no Tk, so no image command). Part of the information
in that file is actually binary,
so I use [binary scan] to convert the bytes to numbers:

binary scan [string index $imageData $pos] value

To my surprise the numbers I get this way are signed, that is: they
range from -128 to 127.

My question: is this platform-dependent behaviour? Is it because the
underlying C run-time library
regards characters as signed? Or is Tcl using signed characters and
this behaviour is by design?

I can easily correct for this: set value [expr {256+$value}], but I
just wonder if this is a - to me -
new kind of platform-dependence.

Regards,

Arjen

I think the numbers are signed by design. If you want unsi
.