Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

write and read binary

84 views
Skip to first unread message

Andre

unread,
Mar 7, 2017, 12:34:03 AM3/7/17
to
Why cannot supports more than 15 character to write and read as below format scan binary;

fconfigure $f -translation binary
set dt [binary format i $data]

I just want to write and read to a binary file. Any suggests or another commands?!

Thanks

Arjen Markus

unread,
Mar 7, 2017, 2:43:47 AM3/7/17
to
You should check the manual page for [binary] - the format you use in the incomplete fragment (where is the data coming from?) means that one single 4-byte integer is taken from the value of the variable data.

If data is a list, you could use: set dt [binary format i* $data] to convert the entire list to a binary string and write that to a file.

Regards,

Arjen

Andre

unread,
Mar 7, 2017, 1:26:18 PM3/7/17
to
HI Arjan,

set data {4342342346567658635656545235676324145436576887878799076767674532423434567704324344324324324325454312413404324324324}

Thanks

Rich

unread,
Mar 7, 2017, 3:49:30 PM3/7/17
to
Please do not top quote - doing so destroys the temporal relationship
between the replies.

Andre <geomo...@gmail.com> wrote:
> On Monday, March 6, 2017 at 11:43:47 PM UTC-8, Arjen Markus wrote:
>> On Tuesday, March 7, 2017 at 6:34:03 AM UTC+1, Andre wrote:
>> > Why cannot supports more than 15 character to write and read as below format scan binary;
>> >
>> > fconfigure $f -translation binary
>> > set dt [binary format i $data]
>> >
>> > I just want to write and read to a binary file. Any suggests or another commands?!
>> >
>> > Thanks
>>
>> You should check the manual page for [binary] - the format you use in the incomplete fragment (where is the data coming from?) means that one single 4-byte integer is taken from the value of the variable data.
>>
>> If data is a list, you could use: set dt [binary format i* $data] to convert the entire list to a binary string and write that to a file.
>>
>> Regards,
>>
>> Arjen
>
> HI Arjan,
>
> set data {4342342346567658635656545235676324145436576887878799076767674532423434567704324344324324324325454312413404324324324}

As Arjen said, you need to read the man page for binary format. The
answers are all in there.

Specifically you need to read the description of the "H" and "h" format
specifiers, and the description of the "*" operator.

Uwe Klein

unread,
Mar 29, 2017, 4:53:58 AM3/29/17
to
>> set data {4342342346567658635656545235676324145436576887878799076767674532423434567704324344324324324325454312413404324324324}
>
> As Arjen said, you need to read the man page for binary format. The
> answers are all in there.
>
> Specifically you need to read the description of the "H" and "h" format
> specifiers, and the description of the "*" operator.
>

In this case ( data is a string anyway you look at it ) imho the
solution is to

puts $fd $data

:-)

Uwe

0 new messages