1

I have a file containing hex representations of code from a small program, and am trying to actually convert it into the program itself.

For example, here is a sample of such text, stored in a file, input.txt:

8d
00
a1
21
53
57
43
48
0e
00
bb

I am using the following BASh snippet to convert the file to a binary file:

rm outfile; while read h; do echo -n ${h}; echo -ne \\x${h} >> outfile; done < input.txt

After opening the output file in VIM:

¡!SWCH»

And then converting it to hex representation via xxd:

0000000: 8d00 a121 5357 4348 0e00 bb0a            ...!SWCH....

This is all good, except for one thing: There is a trailing byte, 0a, trailing at the end of my binary output file. This happens for every program file I work with. How is the trailing 0a being appending to every output binary file? It's not present in my input file.

Thank you.

0

1 Answer 1

2

Simply, use xxd directly from a bash like

xxd outfile > outfile.hex

and you will see, here isn't any 0a.

The 0a is appended somewhere when the vim sends a line to xxd command. If you want convert inside vim - try use

vim -b outfile

what open the outfile in binary mode.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.