Convert binary file from hex little endian to decimal

16 ビュー (過去 30 日間)
Daniel Carlson
Daniel Carlson 2019 年 10 月 9 日
回答済み: Daniel Carlson 2019 年 10 月 14 日
Hi- my first post so go easy.
I get data from a sensor via a RockBlock Iridium Modem. The data come in 50 byte messages. I get an email with the data in Hex (little endian) - here is an example
85cd0a0084a7f6ff884027000b27e5cc0a0031a6f6ff885026000d427acc0a0096a4f6ff886026000c322900605a0002003c
I also get a binary file with the data.
I would like to read the binary file and decode it in matlab. I tried to attach my binary data file but it was not a supported file format so I've included a link to it here
For example, the first 8 bytes correspond to the latitude. I need to convert from little endian to big endian and then to decimal.
  4 件のコメント
Stephen23
Stephen23 2019 年 10 月 9 日
編集済み: Stephen23 2019 年 10 月 9 日
@Daniel Carlson : changing the file extension to .txt is preferred, not everyone wishes to download binary files with MS Office (i.e. trojan and virus-carrying) file extensions, which can trigger all sorts of responses from the OS, virus blockers, etc.
dpb
dpb 2019 年 10 月 10 日
"changing the file extension to .txt is preferred, not everyone wishes to download binary files "
OK, so choose to download or not or have the same content with (purposely) misleading name? It's not like coders don't write stream files as the case here...

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

採用された回答

Daniel Carlson
Daniel Carlson 2019 年 10 月 14 日
So, I think I figured it out.
fname = '300434063383360-608.bin';
fid = fopen(fname);
A = fread(fid);
H = lower(dec2hex(A));
hxstr = [];
for i = 1:length(H)
hxstr = [hxstr H(i,:)];
end
fclose(fid);

その他の回答 (1 件)

Steven Lord
Steven Lord 2019 年 10 月 9 日
The fopen function allows you to specify a machine format when you open the file for reading. Then you can read the data in using the low-level file I/O functions.
If you've already read your data into MATLAB, the swapbytes, typecast, and hex2dec functions may be of use to you.
  1 件のコメント
Daniel Carlson
Daniel Carlson 2019 年 10 月 10 日
Yes, familiar with fopen, but not getting the results that I need. I have this excel worksheet, but having trouble replicating it in Matlab.

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

カテゴリ

Help Center および File ExchangeDownloads についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by