フィルターのクリア

Export char as Hex file

5 ビュー (過去 30 日間)
rickert
rickert 2016 年 11 月 4 日
I have a hexadecimal file that contains ESC/P2 sequences that can be sent to the printer to print a page.
00 00 00 1B 01 40 45 4A 4C 20 31 32 38 34 2E 34 0A 40 45 4A 4C 20 20 20 20 20 0A
1B 40 1B 40 1B 28 52 08 00 00 52 45 4D 4F 54 45 31 53 4E 01 00 00 4D 49 04 00 00 etc...
To import this hex page.prn file I use the following code:
fid = fopen('page.prn');
A = fread(fid, Inf, 'uint8');
fclose(fid);
Fmt = repmat('%02X', 1, 1);
prnfile = sprintf(Fmt, A);
This results in a very long string in Matlab:
0000001B0140454A4C20313238342E340A40454A4C20202020200A...
Now I want to split this long string at each 1B (or other byte) so that I obtain a number of strings. Then I want to make some changes to some of these strings, (decode run length encoding, change counters and repeated values, and compress again) and then I want to combine them again using strcat.
Then I want to export this string into a file that can be read by a hex editor. I tried using fwrite:
fid2 = fopen('newprnfile.prn','w');
fwrite(fid2, prnfile);
fclose(fid2);
But this just results in a plain text file, so with ASCII characters. How can I write the string to a hex file?

回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by