LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   dump hex value in to a binary file (https://www.linuxquestions.org/questions/linux-newbie-8/dump-hex-value-in-to-a-binary-file-4175436027/)

xombboxer 11-07-2012 03:13 AM

dump hex value in to a binary file
 
I am trying to dump hex value 6DA810

into binary file out.bin

but when I open the file in hexeditot it shows asci converted values.

how can i dump hex value as it is into a binary file ?

acid_kewpie 11-07-2012 03:18 AM

why would you write a hex string to a binary file? What does "binary file" even mean?? where is this string coming from in the first place??

xombboxer 11-07-2012 03:26 AM

thanks for the quick reply

i have a bash script

Code:

FILESIZE=6DA810
echo $FILESIZE
printf $FILESIZE > output.bin

I want to dump 6DA810 into a binary file. I tried printf and xdump it did not work (or i dont know how to do it )

eSelix 11-07-2012 03:28 AM

Maybe you mean that
Code:

echo -e '\x6d\xa8\x10' > out.bin

xombboxer 11-07-2012 04:19 AM

Final output is as intended. But how to do it with variable?
\x$FILESIZE Will escape first nibble.

xombboxer 11-07-2012 05:59 AM

Code:

echo -e '\x6da810' > out.bin
how can i achieve this

xombboxer 11-07-2012 08:10 AM

simple echo command with sed and pipes
 
I am trying to dump some hex value to a binary file. i will get the intended result if i do
Code:

echo -e '\xAF\x12\x3A' > out.bin
Will generate a hex dump file. But at the same time if try to do

Code:

int=AF123A
echo -e $int | fold -2 |  paste -sd' ' | sed 's/ /\\x/g' | sed 's/^/'\''\\x/'|sed 's/$/'\''/' > out.bin

Will generate the binary out file as
Code:

'\xAF\x12\x3A'
what is missing here

ntubski 11-07-2012 09:10 AM

I think you are trying to do a reverse hexdump, you can do this with xxd:
Code:

echo AF123A | xxd -r -p > out.bin


All times are GMT -5. The time now is 04:11 PM.