![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284145/image.png)
Need help to translate Lat/long as signed 32bit integer to decimal degrees.
33 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Adam Danz
2020 年 4 月 13 日
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.
採用された回答
James Tursa
2020 年 4 月 13 日
編集済み: James Tursa
2020 年 4 月 13 日
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!