binary scan and signed characters
- From: Arjen Markus <arjen.markus@xxxxxxxxxx>
- Date: Sat, 30 Aug 2008 00:15:34 -0700 (PDT)
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
.
- Follow-Ups:
- Re: binary scan and signed characters
- From: Donal K. Fellows
- Re: binary scan and signed characters
- From: Aric Bills
- Re: binary scan and signed characters
- Prev by Date: Re: TclX loop slow in the default case
- Next by Date: Tcl 8.5 and special numbers
- Previous by thread: core dump in 8.5.4 using SQLite ... more info
- Next by thread: Re: binary scan and signed characters
- Index(es):