hex to bin converter

Nov 10, 2003 4 Replies

Hi All, íÎÅ ÎÁÄÏ ÔÁËÏÊ ËÏÎ×ÅÒÔÅÒ, ËÏÔÏÒÙÊ × ÐÕÓÔÙÅ ÍÅÓÔÁ (ÎÅ ÐÒÏÐÉÓÁÎÎÙÅ × hex-ÆÁÊÌÅ) ÚÁÐÏÌÎÑÌ ÅÄÉÎÉÃÁÍÉ. á ÔÏ Õ ÍÅÎÑ ËÏÎ×ÅÒÔÅÒ ËÏÔÏÒÙÊ ÚÁÐÏÌÎÑÅÔ ÎÕÌÑÍÉ É ÐÏÔÏÍ ÓÌÏÖÎÏ ÐÏÄÓÞÉÔÙ×ÁÔØ ËÏÎÔÒÏÌØÎÕÀ ÓÕÍÍÕ. õ ËÏÇÏ ÔÁËÏÊ ÅÓÔØ ÐÏÓËÁÖÉÔÅ ÇÄÅ ÌÅÖÉÔ. ÷ÁÓÉÌÉÊ


Mon Nov 10 2003 19:35, Vasiliy Zharkov wrote to All:

VZ> Hi All, VZ> íÎÅ ÎÁÄÏ ÔÁËÏÊ ËÏÎ×ÅÒÔÅÒ, ËÏÔÏÒÙÊ × ÐÕÓÔÙÅ ÍÅÓÔÁ (ÎÅ ÐÒÏÐÉÓÁÎÎÙÅ × VZ> hex-ÆÁÊÌÅ) ÚÁÐÏÌÎÑÌ ÅÄÉÎÉÃÁÍÉ. á ÔÏ Õ ÍÅÎÑ ËÏÎ×ÅÒÔÅÒ ËÏÔÏÒÙÊ ÚÁÐÏÌÎÑÅÔ VZ> ÎÕÌÑÍÉ É ÐÏÔÏÍ ÓÌÏÖÎÏ ÐÏÄÓÞÉÔÙ×ÁÔØ ËÏÎÔÒÏÌØÎÕÀ ÓÕÍÍÕ. õ ËÏÇÏ ÔÁËÏÊ ÅÓÔØ VZ> ÐÏÓËÁÖÉÔÅ ÇÄÅ ÌÅÖÉÔ. VZ> ÷ÁÓÉÌÉÊ

formatting link
WBR, àÒÉÊ.

Hallo Vasiliy!

VZ> íÎÅ ÎÁÄÏ ÔÁËÏÊ ËÏÎ×ÅÒÔÅÒ, ËÏÔÏÒÙÊ × ÐÕÓÔÙÅ ÍÅÓÔÁ (ÎÅ ÐÒÏÐÉÓÁÎÎÙÅ × VZ> hex-ÆÁÊÌÅ) ÚÁÐÏÌÎÑÌ ÅÄÉÎÉÃÁÍÉ. ëÏÇÄÁ-ÔÏ × ÄÅÔÓÔ×Å ÐÉÓÁÌ. óÔÉÌØ ËÏÒÑ×ÙÊ, ÎÏ ÒÁÂÏÔÁÅÔ ;) ëÏÍÐÉÌÑÌÏÓØ ÂÏÒÌÁÎÄÏÊ ÐÏÄ OS/2. ðÏÄ ×ÉÎÄÏÊ ÔÏÖÅ ÄÏÌÖÎÏ ÓËÏÍÐÉÌÑÔØÓÑ. ðÏÄ äïóÏÍ - ÎÅ ÄÏÌÖÎÏ.

#include <stdio.h>

#include <mem.h>

#define DATASIZE 0x10000 #define FILLER 0xff

unsigned char Data[DATASIZE];

int hextobin(char *str,int digits) { int rc=0; while (digits--) { rc <<= 4; if ((*str >= '0') && (*str <= '9')) rc |= (*str)-'0'; else if ((*str >= 'A') && (*str <= 'F')) rc |= (*str)-'A'+10; else return -1; str++; } return rc; }

int main(int argc, char **argv) { FILE *fp; char str[80]; int i,line,crc,size,addr,type,databyte; if (argc != 3) { printf ("USAGE: HEX2BIN infile.hex outfile.bin\n"); return -1; } memset(Data,FILLER,DATASIZE); fp = fopen(argv[1],"rt"); if (fp == NULL) { printf ("Unable to open file %s\n",argv[1]); return 1; } for (line=1;;line++) { crc=0; str[0] = 0; fgets(str,79,fp); if (feof(fp)) break; if (str[0] != ':') { printf ("Error in file %s at line %d\n",argv[1],line); return 2; } size = hextobin(str+1,2); addr = hextobin(str+3,4); type = hextobin(str+7,2); for (i=0;i<size;i++) { databyte = hextobin(str+9+i*2,2); if (databyte==-1) break; crc+=databyte; str[i] = databyte; } if (databyte!=-1) databyte = hextobin(str+9+i*2,2); if ((size==-1) || (addr==-1) || (type==-1) || (databyte==-1)) { printf ("Error in file %s at line %d\n",argv[1],line); return 3; } crc+=size; crc+=(addr&0xff); crc+=(addr>>8); crc+=type; crc+=databyte; if ((crc&0xff) != 0) { printf ("CRC error in file %s at line %d\n",argv[1],line); return 4; } if (type!=0) continue; if (size==0) continue; memcpy(Data+addr,str,size); } fclose(fp); fp = fopen(argv[2],"wb"); if (fp == NULL) { printf ("Unable to create file %s\n",argv[2]); return 4; } fwrite(Data,1,DATASIZE,fp); fclose(fp); return 0; }

WBR Slavik A. Komarov

äÏÂÒÏÇÏ ÚÄÏÒÏרÑ, Vasiliy!

10 Nov 03 19:35, Vasiliy Zharkov ÎÁÐÉÓÁÌ ÄÌÑ All:

VZ> íÎÅ ÎÁÄÏ ÔÁËÏÊ ËÏÎ×ÅÒÔÅÒ, ËÏÔÏÒÙÊ × ÐÕÓÔÙÅ ÍÅÓÔÁ (ÎÅ ÐÒÏÐÉÓÁÎÎÙÅ × VZ> hex-ÆÁÊÌÅ) VZ> ÚÁÐÏÌÎÑÌ ÅÄÉÎÉÃÁÍÉ. á ÔÏ Õ ÍÅÎÑ ËÏÎ×ÅÒÔÅÒ ËÏÔÏÒÙÊ ÚÁÐÏÌÎÑÅÔ ÎÕÌÑÍÉ É ÐÏÔÏÍ VZ> ÓÌÏÖÎÏ ÐÏÄÓÞÉÔÙ×ÁÔØ ËÏÎÔÒÏÌØÎÕÀ ÓÕÍÍÕ. õ ËÏÇÏ ÔÁËÏÊ ÅÓÔØ ÐÏÓËÁÖÉÔÅ ÇÄÅ VZ> ÌÅÖÉÔ.

ÍÎÏÇÉÅ ÌÉÎËÅÒÙ ÕÍÅÀÔ ÚÁÂÉ×ÁÔØ ÎÅÉÓÐÏÌØÚÏ×ÁÎÎÕÀ ÐÁÍÑÔØ ÅÄÉÎÉÃÁÍÉ

WBR, óÅÒÇÅÊ. ICQ: 101347299

... ëÒÁÓÏÔÁ ÔÒÅÂÕÅÔ ÖÅÒÔ×. é × ÏÓÎÏ×ÎÏÍ ÜÔÉ ÖÅÒÔ×Ù ÍÕÖØÑ...

ðÒÉ×ÅÔ Vasiliy!

10 Nov 03 19:35, Vasiliy Zharkov ÐÉÓÁÌ All:

VZ> íÎÅ ÎÁÄÏ ÔÁËÏÊ ËÏÎ×ÅÒÔÅÒ, ËÏÔÏÒÙÊ × ÐÕÓÔÙÅ ÍÅÓÔÁ (ÎÅ ÐÒÏÐÉÓÁÎÎÙÅ × VZ> hex-ÆÁÊÌÅ) ÚÁÐÏÌÎÑÌ ÅÄÉÎÉÃÁÍÉ.

man objcopy ÎÁ ÐÒÅÄÍÅÔ --gap-fill.

óÏÂÓÔ×ÅÎÎÏ, ×ÏÔ ÞÔÏ ÔÁÍ ÎÁÐÉÓÁÎÏ:

--gap-fill=val Fill gaps between sections with val. This operation applies to the load address (LMA) of the sections. It is done by increasing the size of the section with the lower address, and filling in the extra space created with val.

VZ> õ ËÏÇÏ ÔÁËÏÊ ÅÓÔØ ÐÏÓËÁÖÉÔÅ ÇÄÅ ÌÅÖÉÔ.

ìÅÖÉÔ ÎÁ
formatting link
× ËÏÍÐÌÅËÔÅ binutils.

VZ> ÷ÁÓÉÌÉÊ

÷ÓÅÇÏ ÎÁÉÌÕÞÛÅÇÏ, [Team PCAD 2000] áÌÅËÓÅÊ í. ... ðÉÒÏÖÏË ×ÁÒÅÎÙÊ Ó ×ÁÒÅÎØÅÍ.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required