1.

Solve : file.txt to file.hex?

Answer»

i not know if it's easy to do but .. try to ask:

i have file.txt with

Quote

02E37CFE2445E08C04EF2049445FE3E6
03F5ED7538AA386C9C38087546FAC0F4
045F94AE3C85B806F73CEFF523D069E8
0499247205BE3F73DF99299D9525A7AF
08F8D5130625DEABDED4A7988DF1259D

at the end of every line i have 0d0a (i think "return" hex code)

i need to translate this line into hex code for make hex file

16byte, delete 0d0a, attach next 16 byte and go on

02 e3 7c fe 24 .... usable like hex dataexplain more clearly what you are trying to do.
you said you have "0d0a" at end of every line, but i don't see it in your sample file.
also, GIVE a sample of your desired output.You need to write a program to do that.

Here is one in QBasic. If you have QBasic in your DOS system, then SAVE this program as z.bas and your data as z.dat and do
QBasic /run z

That will produce z.com, your hex file of 80 characters.

Mac

Code: [Select]OPEN "z.dat" FOR INPUT AS #1
OPEN "z.com" FOR OUTPUT AS #2
DO WHILE NOT EOF(1)
  LINE INPUT #1, l$
  PRINT l$; "<---"
  IF LEN(l$) <> 32 THEN PRINT "Wrong length record": SYSTEM
  FOR i = 1 TO 32 STEP 2
    v1 = INSTR("0123456789ABCDEF", MID$(l$, i, 1))
    v2 = INSTR("0123456789ABCDEF", MID$(l$, i + 1, 1))
    IF v1 * v2 = 0 THEN PRINT "Non-hex in file": SYSTEM
    v3 = ((v1 - 1) * 16) + (v2 - 1)
    PRINT #2, CHR$(v3);
  NEXT i
LOOP
CLOSE
SYSTEM
i have one txt with more hex data (or i make one by copy/paste part from one other big txt)

if i see with hex editor the txt file i see at the end of every line one CR like 0d0a (2 byte)

now i need to make from this txt file one hex file

....

one functional way are to delete manually all "CR":

Quote
02E37CFE2445E08C04EF2049445FE3E603F5ED7538AA386C9C38087546FAC0F4
045F94AE3C85B806F73CEFF523D069E8
0499247205BE3F73DF99299D9525A7AF
08F8D5130625DEABDED4A7988DF1259D

like first two line and paste it into hex editor ...

but are about 189 line  frankly, i don't understand. Since you are using hex editor to see the file, does the editor have any way to save it as hex??with hex editor i see hex data (the hex data i need into hex file) like ASCII code into right windows Quote
frankly, i don't understand.

Two options:

He has a text file, not a hex file. The text file has 32 characters in the range 0-F on a line. Each line is terminated by a line-feed plus carriage return as is true for all text files. So if first two lines are this in the text editor:

02E37CFE2445E08C04EF2049445FE3E6
03F5ED7538AA386C9C38087546FAC0F4

then in the hex editor, he sees this (starting with E3E6 at the end of line one:

E 3 E 6 CRLF0 3
4533453613103033

And if so, my QBasic program will work.

Otherwise, he ALREADY has a file where the characters are 0-255, but each 16 characters is delimited by the crlf. He just wants to eliminate the crlf.

This can be DONE by
LINE INPUT #1, L$
PRINT #2, L$;

The semi-colon will eliminate the crlf.

Mac
i'm really newbie  :-?

i have just maked Qbasic program and it work (i not have test all hex code), so i need to put into little tool directory Qbasic executable

i'm searching for one more little (in disk space) solution

really thanks QbasicMac Quote
You need to write a program to do that.

Here is one in QBasic. If you have QBasic in your DOS system, then save this program as z.bas and your data as z.dat and do
QBasic /run z

That will produce z.com, your hex file of 80 characters.

Mac

Code: [Select]OPEN "z.dat" FOR INPUT AS #1
OPEN "z.com" FOR OUTPUT AS #2
DO WHILE NOT EOF(1)
  LINE INPUT #1, l$
  PRINT l$; "<---"
  IF LEN(l$) <> 32 THEN PRINT "Wrong length record": SYSTEM
  FOR i = 1 TO 32 STEP 2
    v1 = INSTR("0123456789ABCDEF", MID$(l$, i, 1))
    v2 = INSTR("0123456789ABCDEF", MID$(l$, i + 1, 1))
    IF v1 * v2 = 0 THEN PRINT "Non-hex in file": SYSTEM
    v3 = ((v1 - 1) * 16) + (v2 - 1)
    PRINT #2, CHR$(v3);
  NEXT i
LOOP
CLOSE
SYSTEM

one other question ...

for me it's usefull to have into beginning list (TXT FILE) some text word to esplain some information but, of course, when i trasform file.txt to file.hex thie word not have trasformed

can you adjust this program for not consider, for example, line begin with # char ?

Quote
02E37CFE2445E08C04EF2049445FE3E6
03F5ED7538AA386C9C38087546FAC0F4
#
# text for infomation about and not to translate
#
045F94AE3C85B806F73CEFF523D069E8
0499247205BE3F73DF99299D9525A7AF
08F8D5130625DEABDED4A7988DF1259D

thanks againscriptors,

I think this is what you want...

If text1.txt contains:
[edit]02E37CFE2445E08C04EF2049445FE3E6
03F5ED7538AA386C9C38087546FAC0F4
#
# text for information about and not to translate
#
045F94AE3C85B806F73CEFF523D069E8
0499247205BE3F73DF99299D9525A7AF
08F8D5130625DEABDED4A7988DF1259D [/edit]

Then you want to convert it into one continuous:
[edit]02 E3 7C FE 24 45 E0 8C 04 EF 20 49 44 5F E3 E6 03 F5 ED 75 38 AA 38 6C 9C 38 08 75 46 FA C0 F4 04 5F 94 AE 3C 85 B8 06 F7 3C EF F5 23 D0 69 E8 04 99 24 72 05 BE 3F 73 DF 99 29 9D 95 25 A7 AF 08 F8 D5 13 06 25 DE AB DE D4 A7 98 8D F1 25 9D[/edit]


The following batch script will do the job:
[edit]echo off
(
    for /f "eol=#" %%a in (file1.txt) do (
        set hx=%%a
        for /l %%n in (0,2,31) do (
            call echo.%%hx:~%%n,2%%
        )
    )
)>%~dpn0.htm[/edit]

Copy the code into a new batch file named myhex.bat.  Have text1.txt in the same directory.
Executing myhex.bat will create a new file named myhex.htm that you can open in a web browser and then copy your hex code from there into the hex editor.

DOS IT HELP?


Discussion

No Comment Found