Convert binary file from hex little endian to decimal
Show older comments
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 Comments
"I tried to attach my binary data file but it was not a supported file format..."
What possessed TMW to do this for a programming forum is beyond comprehension...but you can get around it by simply renaming the file to use an allowed extension; it looks only at the file name, not the content.
What's the corresponding result for the above?
There's 100 characters in the above; that isn't divisible by 8. I presume that's just artifact of how much you pasted in and there are 12*8=96 "real" values plus 4 bytes from subsequent?
Daniel Carlson
on 9 Oct 2019
@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
on 10 Oct 2019
"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...
Accepted Answer
More Answers (1)
Steven Lord
on 9 Oct 2019
0 votes
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 Comment
Daniel Carlson
on 10 Oct 2019
Categories
Find more on Standard File Formats in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!