Convert hex data to string

5 ビュー (過去 30 日間)
Bob Thompson
Bob Thompson 2018 年 7 月 20 日
コメント済み: Bob Thompson 2018 年 7 月 20 日
I have a file which contains hex data of the form: '45 2B 30 30 0D 0A 20 20 20 30 2E 30 30 30 30 45'.
I'm trying to get a piece of code which will read the data and convert it from hexadecimal to a character string. I know that each of the pairs of numbers corresponds to a single character (the file shows me the translation, but not in a usable format) that could be alphabetical, numeric, or symbolic. I have so far been unable to locate a script which will properly convert to characters.
I am using the following to read the file into lines and strings for easier consideration.
fid = fopen('file.dat');
A = fread(fid, Inf, 'uint8');
fclose(fid);
Fmt = repmat('%02X ', 1, 16);
Fmt(end) = '*';
S = sprintf(Fmt, A);
C = regexp(S, '*', 'split');
I am not looking to use hex2dec, as this gives numeric returns only.
Sorry, but no, I cannot provide a sample file, though the string at the beginning is a sample from the file.

採用された回答

Fangjun Jiang
Fangjun Jiang 2018 年 7 月 20 日
try A=importdata('file.dat'), you might get what you want in A.textdata
  1 件のコメント
Bob Thompson
Bob Thompson 2018 年 7 月 20 日
Thanks, it's always nice to know MathWorks thinks of things that I don't.

サインインしてコメントする。

その他の回答 (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