Need help to translate Lat/long as signed 32bit integer to decimal degrees.

20 visualizaciones (últimos 30 días)
This one is for you math lovers.
I need to convert latitude and longitude given as:
"In WGS.84 in two’s complement. Range -90 <= latitude <= 90 deg. LSB = 180/230 degrees. = 1.6764 * 10-07 degrees."
I can't quite get my head around the order of operations I need to do to get this to decimal degrees. Clearly I need to deal with the two's compliment and figure out the sign and honestly, I'm not sure what "LSB=180/230" is trying to tell me.
Example from Wireshark, which has a built-in disector for the ASTERIX protocol.
  • Latitude packet: 0f3b3111 // Latitude disected value: 42.8377990610898
  • Longitude packet: e4d742fa // Longitude disected value: -76.3850651308894
Wireshark's values are correct. But I haven't found the right magic to translate the hex to decimal degrees in Matlab.
Any help would be much appreciated.
  4 comentarios
Roger Pierson
Roger Pierson el 13 de Abr. de 2020
The line in bold comes from the interface specification for the protocol I'm dealing with (ASTERIX). It explans how the data is encoded.
I'm trying to figure out how to decode that and get human understandable coordinates out of it.
Adam Danz
Adam Danz el 13 de Abr. de 2020
I'm not familiar with Asterix. If your question is how to interpret that, perhaps there's are some online resources or a forum for Asterix that would be helpful. If you can explain that line and what you need to do with it in Matlab, I'd be glad to help.

Iniciar sesión para comentar.

Respuesta aceptada

James Tursa
James Tursa el 13 de Abr. de 2020
Editada: James Tursa el 13 de Abr. de 2020
The LSB is probably telling you that the value of the Least Significant Bit of the integer value is 1.6764e-07. Since MATLAB already uses 2's complement storage for its signed integer classes, all you have to do is some calls with cast( ) and typecast( ) to get the conversion. E.g., on WIN64 I get this result using your posted conversion factor:
>> double(typecast(uint32(hex2dec('0f3b3111')),'int32'))*1.6764e-07
ans =
42.838293927
>> double(typecast(uint32(hex2dec('e4d742fa')),'int32'))*1.6764e-07
ans =
-76.38594753768
Not exactly matching your numbers, but pretty close and probably all that can be expected given the number of significant digits of the conversion factor that I am using. If I had the full precision of the conversion factor I could probably get an exact match. Backing out the conversion factor from your examples I get an exact match:
>> double(typecast(uint32(hex2dec('0f3b3111')),'int32'))*1.6763806343078619e-07
ans =
42.8377990610898
>> double(typecast(uint32(hex2dec('e4d742fa')),'int32'))*1.6763806343078619e-07
ans =
-76.3850651308894
On your machine there might need to be a swapbytes( ) thrown in before the double( ) conversion.
I'm still not sure what that 180/230 means or how it is related to the conversion factor ...
  3 comentarios
Roger Pierson
Roger Pierson el 13 de Abr. de 2020
Positively brilliant. It works in my application perfectly. Thank you!
Roger Pierson
Roger Pierson el 13 de Abr. de 2020
For future readers: I ran this code on a MacBook and it ran fine without any changes.

Iniciar sesión para comentar.

Más respuestas (1)

Adam Danz
Adam Danz el 13 de Abr. de 2020
Editada: Adam Danz el 13 de Abr. de 2020
  1 comentario
Roger Pierson
Roger Pierson el 13 de Abr. de 2020
Thanks, but I do not have the mapping toolbox.
Also, wouldn't i have to manipulate the raw values somehow to reverse the two's compliment?

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by