Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2003-12-03
16:21 • Ticket [852280ffff] binary format conversion error status still Closed with ... artifact: 515809e957 user: dkf
15:36 • Ticket [852280ffff]: 4 changes artifact: b75341e91f user: nobody
2003-12-02
07:02 • Closed ticket [852280ffff]. artifact: 73e25fbaea user: dkf
2003-12-01
19:57 • New ticket [852280ffff]. artifact: fcf3b0ba11 user: nobody

binary format conversion error

Closed / Invalid852280ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2003-12-01 19:57:40
Hi all !

I am using Linux 9 w Tcl 8.4.4.-34.
Got a funny mistake from Tcl, maybe
the new release fixes it, haven't checked
it yet.

Trying to convert string to binary double,
32Bit-float like this:

set datei [open "test.bin" w]
puts -nonewline $datei [binary format "f" [format "%
E" 0.3705]]
close $datei

Problem: binary number yields
0.1869516 !

Also tried:
"0.3705"
"3.705E-1"
instead of 0.3705 but problems still there.

However, only some numbers are converted wrongly.
E.g. 0.364 converts correctly !
To me, it looks arbitrary, but I see it on all my graphs
(Exporting data from my db to scilab).
Therefore I need exactly this binary format, no other 
avail. 

Ok. Trying new version but don't think this bug
is resolved.

Thanks in advance for the help

Bjoern
dkfplain2003-12-02 07:02:28
Logged In: YES 
user_id=79902

I bet that if you set your output channel to be a binary
channel, everything will work.  Add the following line after
the [open] and before the [puts] and see if it helps...
   fconfigure $datei -translation binary
nobodyplain2003-12-03 15:36:24
Logged In: NO 

Thanks dkf,
works so far with the addition of fconfigure.
It's still weird in my opinion. 
The previous versions of Tcl did not require
this command to work properly.

Bjoern
dkfplain2003-12-03 16:21:29
Logged In: YES 
user_id=79902

That could be one of two things:
a) You've previously been using 8.0 which didn't have the
encoding subsystem in the first place.  :^)
b) You've previously been using 8.1, 8.2 or 8.3 which got
the default encoding of all channels wrong (arguably). In
8.4 we switched the method used for computing the default
encoding to something that does a better job for most
purposes, but you're now not using ISO8859-1 as your default
encoding (which just happened to work for binary data almost
by chance.)
Log in (anonymous is fine) to add a comment.