Converting downloaded binary data to decimal
Mostrar comentarios más antiguos
Hey folks,
I'm using a web service that is responding to queries with binary data and I'm really struggling to convert this to a more usable format. Fortunately, the service does provide an example data case and they explain the formats and definitions. The problem is that I'm not familiar with converting data types like this and haven't found the right recipe.
I'm attaching a .mat file with three examples in it. Each example has what the web service query returned (raw), what the web service documentation says should be returned (not sure what this format is called, but I called it hex... maybe it's unicode???), and what the web service documentation says the data represents (decimal values).
Example 1: The Matlab web query returns "A33" (without quotations). The documentation says this should show up as "47 97 33 33". Is this unicode, hex, other??? I call it "hex" in my file format. According to documentation, this represents a float number of length (8-bit bytes) of 4. In this case, the represented number is "18.90". Furthermore, they define "Float" as a single-precision floating point 32-bit IEEE 754 size/format.
I'm struggling to get the raw "A33" to look like the documentation, but I can get close if I use:
dec2hex(unicode2native('A33','US-ASCII')) % returns "41 1A 33 33" (1A element SHOULD be 97)
Example 2: raw returned data is "G" (without quotes). Documentation says this should be "47 0F C6 14" that represents 3,680,608. Here's what I get:
dec2hex(unicode2native('G','US-ASCII')) % returns "47 0F 1A 14" (1A element SHOULD be C6)
Example 3: raw returned data is " jh" (without quotes). Documentation says this should be "00 00 01 16 6A E0 68 80" that represents a timestamp of November 23, 2007 (I assume it's a number of days measured from Jan 1, 1970, or perhaps from year 0. What I get:
dec2hex(unicode2native(' jh','US-ASCII')) % returns "20 20 01 16 6A 1A 68 1A" (four of these elements are wrong)
So here are my questions on the above three examples:
1) Do you have input on how I'm trying to convert the raw data to usable numbers? I'm totally unfamiliar with this area of computing.
2) Once I do get the raw data to look like what the documentation specifies (e.g., "47 97 33 33"), do you know how I convert it to decimal (e.g., 18.90)?
3) Is it possible that the web request itself is not correct and the data I'm getting back does not match what is expected? In this case, could it be something where I need to change the web options in the web request?
Any input on this matter is much appreciated!!!
Thanks,
Paul
Respuesta aceptada
Más respuestas (1)
Rohit chand
el 9 de Jun. de 2020
0 votos
Your data logger shows the decimal numbers 47 and 21875.
1 comentario
Walter Roberson
el 9 de Jun. de 2020
Could you explain how you derive that information?
Categorías
Más información sobre String Parsing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!