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 07-19-2006, 02:09 PM   #1
linx win
Member
 
Registered: Jan 2004
Posts: 390

Rep: Reputation: 31
converting a hex file to binary


I need to convert a hex file named: WBoot.hex (firmware file) to binary. The following post:
http://sourceforge.net/mailarchive/f...forum_id=43894
suggested the following script:
PHP Code:
int main(int argcchar ** argv)
      {
           
unsigned int bp[] = {
          
#include "WBoot.hex"
     
};
     
write(1bpsizeof(bp));
      } 
I copied it to a new file, made it executable and run it but I got the following:

./convert: line 1: syntax error near unexpected token `('
./convert: line 1: `int main(int argc, char ** argv)'

I tried:
$ xxd -r WBoot.hex cxacru-bp.bin
but I got very small file which did not work.

Any idea?
 
Old 07-19-2006, 02:40 PM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
thats not a script, that is c code.. it will have to be compiled, and it does not look complete. is there any #include at the top of the file? i think write is in <unistd.h>
 
Old 07-19-2006, 03:31 PM   #3
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
xhi is right; you need to #include <unistd.h> and maybe some other files (check `man 2 write`) at the top of the file first. Then you have to compile it with gcc (in other words `gcc name-of-file.c`) and run the resulting a.out to get your binary file; redirect the output (using the > operator in your shell) to cxacru-bp.bin
 
Old 07-20-2006, 03:04 AM   #4
linx win
Member
 
Registered: Jan 2004
Posts: 390

Original Poster
Rep: Reputation: 31
Thanks. I got my modem to work finally. Here is the final file code after including your comments:

Quote:
#include <unistd.h>
int main(int argc, char ** argv)
{
unsigned int bp[] = {
#include "WBoot.hex"
};
write(1, bp, sizeof(bp));
}
 
  


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 convert a float to its binary or hex representation in Python? zero79 Programming 1 09-01-2005 10:19 AM
gnome-calculator - converting between numeric bases (eg hex to binary) jht2k Linux - General 2 07-01-2005 09:12 AM
Binary to Hex Ascii converter carboncopy Slackware 1 05-28-2004 09:09 AM
C, converting hex to text Sm0k3 Programming 2 10-11-2003 04:29 AM
converting fake hex to decimal in c acid_kewpie Programming 10 08-20-2003 02:29 PM

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

All times are GMT -5. The time now is 07:06 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
Open Source Consulting | Domain Registration