LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-07-2012, 04:13 AM   #1
xombboxer
Member
 
Registered: Apr 2011
Posts: 63

Rep: Reputation: 0
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 ?
 
Old 11-07-2012, 04:18 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
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??
 
Old 11-07-2012, 04:26 AM   #3
xombboxer
Member
 
Registered: Apr 2011
Posts: 63

Original Poster
Rep: Reputation: 0
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 )
 
Old 11-07-2012, 04:28 AM   #4
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,252

Rep: Reputation: 313Reputation: 313Reputation: 313Reputation: 313
Maybe you mean that
Code:
echo -e '\x6d\xa8\x10' > out.bin
 
Old 11-07-2012, 05:19 AM   #5
xombboxer
Member
 
Registered: Apr 2011
Posts: 63

Original Poster
Rep: Reputation: 0
Final output is as intended. But how to do it with variable?
\x$FILESIZE Will escape first nibble.
 
Old 11-07-2012, 06:59 AM   #6
xombboxer
Member
 
Registered: Apr 2011
Posts: 63

Original Poster
Rep: Reputation: 0
Code:
echo -e '\x6da810' > out.bin
how can i achieve this
 
Old 11-07-2012, 09:10 AM   #7
xombboxer
Member
 
Registered: Apr 2011
Posts: 63

Original Poster
Rep: Reputation: 0
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
 
Old 11-07-2012, 10:10 AM   #8
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,013

Rep: Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225
I think you are trying to do a reverse hexdump, you can do this with xxd:
Code:
echo AF123A | xxd -r -p > out.bin
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to replace 10th and 11th byte in a hex dump Heraton Linux - Newbie 8 02-20-2012 01:11 PM
[SOLVED] How do I get a simple hex dump in gdb gung Linux - Software 3 05-03-2010 12:38 AM
LXer: Doing a Reverse Hex Dump LXer Syndicated Linux News 0 06-03-2008 03:50 AM
converting a hex file to binary linx win Programming 3 07-20-2006 04:04 AM
strange hex dump of floppy Berhanie Linux - General 2 02-07-2004 12:53 PM


All times are GMT -5. The time now is 08:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration