Reading in Intel Hex file to sort C ++

I need to read in an Intel Hex file that looks something like this:

:0300000002F8D42F
:07000300020096000000005E
:07000B000200B50000000037
:030013000200D414
:03001B000200F3ED  

(Yes, some lines are missing, and sometimes one line contains only 1 byte)
: - initial code
First 2 bytes - number of bytes
Next 4 - memory address
Next 2 - record type
Other data (except for the last 2 bytes)
last 2 bytes - checksum
Read more here (wikipedia)

I need to end up with something like this (no periods, only there for readability):

:10.addr.RT.10bytesofdata.CK

If there is no data from the file for the address, I fill it with "FF"

, , , .
(?), 2D, .

[BC][ADDR][RT][b1][b2][b3][b4][b5][b6][b...16][ck]
[BC][ADDR][RT][b1][b2][b3][b4][b5][b6][b...16][ck]  
...  

, .
Visual Studio.
, , .

, , - :

fscanf_s(in_file,"%2X", &BC);
fscanf_s(in_file,"%4X", &ADDR);
fscanf_s(in_file,"%2X", &RT);  

:

fprintf_s(out_file,"%2X", BC);
fprintf_s(out_file,"%04X", ADDR);   //this pads with zeros if needed and forces 4 "digits"  
fprintf_s(out_file,"%2X", RT);  

. , - .

+3
2

Dictionary<RT, byte[]> . , , 0xFF, .

, Dictionary<RT, List<byte>>, , 4 64k, .

+1

2D- - 1D, ( ) . FF. :

  • .

, 10 (10h?) , , .

+1

Source: https://habr.com/ru/post/1756027/


All Articles