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

export hex

45 views
Skip to first unread message

Andre

unread,
Jan 21, 2018, 11:55:06 PM1/21/18
to
Hi All,

How to export the hexadecimal from a files by 1024 bytes.

set in [open files.tx r]
set rd [read $in]
set out [open output.txt w]
binary scan $rd H* hex
....
....

Thank in advance!

Gerald Lester

unread,
Jan 22, 2018, 12:15:52 AM1/22/18
to
Is the input file binary or ASCII or what?

What do you mean "by 1024 bytes"?

Is this a homework project?

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+----------------------------------------------------------------------+

Andre

unread,
Jan 22, 2018, 1:22:41 AM1/22/18
to
I mean that How to export maximal 1024 bytes every line. Actually, I just need split the hex words every 1024 hex characters in every line.

I was tried to export the hex string like puts $out $hex but this script just one line and make my text editor very very low and crast.

Thanks

Gerald Lester

unread,
Jan 22, 2018, 1:34:18 AM1/22/18
to
On 01/22/2018 12:22 AM, Andre wrote:
> I mean that How to export maximal 1024 bytes every line. Actually, I just need split the hex words every 1024 hex characters in every line.
>
> I was tried to export the hex string like puts $out $hex but this script just one line and make my text editor very very low and crast.

Read the man/help/documentation pages for the following commands:
string (pay attention to the range and lenght subcommands)
while

Rich

unread,
Jan 22, 2018, 7:23:19 AM1/22/18
to
Gerald Lester <Gerald...@kng-consulting.net> wrote:
> On 01/21/2018 10:55 PM, Andre wrote:
>> Hi All,
>>
>> How to export the hexadecimal from a files by 1024 bytes.
>>
>> set in [open files.tx r]
>> set rd [read $in]
>> set out [open output.txt w]
>> binary scan $rd H* hex
>> ....
>> ....
>
> Is the input file binary or ASCII or what?
>
> What do you mean "by 1024 bytes"?
>
> Is this a homework project?

Smells *very much* like a homework project.

Andreas Leitgeb

unread,
Jan 23, 2018, 6:36:25 PM1/23/18
to
Andre <geom...@gmail.com> wrote:
> I mean that How to export maximal 1024 bytes every line. Actually, I just
> need split the hex words every 1024 hex characters in every line.

It may be easier to tell [read $in] to only read 512 bytes, that will
then turn into 1024 hexdigits.

But you will need to put some of the commands into a loop.

Also, I'd suggest you open the file with mode "rb" to make sure tcl
doesn't translate the bytes in some way, e.g. turning a \r or \r\n
into a single \n .

> I was tried to export the hex string like puts $out $hex but this
> script just one line and make my text editor very very low and crast.

Tcl doesn't have any built-in function to just split a string every <n>
chars. I missed such, too, a couple of times, and fell back to rather
ugly workarounds, like [regexp -all -inline -- ".{0,1024}" $hex]
but that doesn't "feel" right to me.

In your case, reading just 512-byte chunks from the file in a loop
and translating each as you did, is preferrable over creating a string
double as large as the original file and then splitting it up in memory.

0 new messages