LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-18-2012, 03:57 AM   #1
voda87
LQ Newbie
 
Registered: Mar 2011
Posts: 6

Rep: Reputation: 0
Post Convert a file of binery values to hex file


Hi,

I have a file that looks like that:

11000010
00000000
00010001
00100000
11110111
00000000
10001100
00000001
10110110


and so on for thousands of lines...

i want to convert it to a file that looks like this:

FA D7 67 A6 0F 00 61 3C
F1 A3 47 3A 08 00 81 1C
DD 13 67 AA 5F 00 11 3C
FA D3 69 AA 0F 00 61 3B

i just made up the HEX values, they don't much in my example...

i found this to be what I'm looking for but for a single value :
Code:
echo "obase=16;ibase=2; 11000100" | bc
Thanks for your help guys.
 
Old 12-18-2012, 08:05 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Just do a while loop on your file:

Code:
cat file |while read binary
do echo "obase=16;ibase=2;$binary" |bc
done
That sets each line of the file to the variable named binary (you could name it anything) then uses that variable in the bc string command string you'd already figured out.
 
  


Reply



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
how to find free software to convert an imported .dst file to a .pes file. seabee 2 Linux - Software 3 08-28-2012 03:01 PM
convert multiple file in directory: ascii to hex in perl fad216 Programming 3 04-10-2011 12:47 PM
Hex values converting Inconsistently TheCrow33 Linux - General 2 12-20-2010 11:17 AM
How to convert a hex file to an ASCII file? lxnbie Linux - Server 1 09-08-2010 03:49 AM
Convert characters to hex values in perl pjz Programming 3 12-08-2005 08:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:07 AM.

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
Open Source Consulting | Domain Registration