Convert unknown Hex digits to a Longitude and Latitude

ε祈祈猫儿з 提交于 2019-12-04 12:51:50

I think the values are in 32-bit floating point. However, the bytes are slightly shifted in the stream that you show. Taking longitude first: 100.47629 in 32-bit floating point is 42C8F3DC these are bytes 10 through 13 in your stream (Least significant byte first). For latitude 5.13637 in 32-bit floating point is 40A45D24 these are bytes 14 through 17 but it's 40A45D14 in the byte stream so it's off a little in the least significant decimal digit (Again, it's least significant byte first).

I worked with a Motorola GPS module once and the documentation said that the two hexes represented int types.

In your case, you might want to look at the documentation as well. If you know the model number, you can just google it. Here is the documentation link for the motorola GPS I used.

Motorola GPS Module

I also took the liberty to do some calculations for you. If your lattitude was indeed

0x1442c8f3 

(endianness does make a difference here). The integer equivalent is

339921139 

in decimal system. If you divide that by 3600000 milliarcseconds (where 1 deg = 60 min = 60 * 60 s = 60*60*1000 ms) you get

94.4225386

deg, which is close to your expectations. There isn't enough data to validate it but I believe most of the GPS modules return the milliarcseconds for both latitude and longitude.)

Assuming the hex codes represent unencrypted 32-bit floating point numbers (they might not do), you could try reading them into a C program and printing them out using printf("%f").

Don't forget that the words could have both endianness, i.e. the first one could be F3 C8 42 14 or 14 42 C8 F3 (bytes reversed).

Try it both ways and see if you get anything useful.

I wasn't able to get anything quickly from this online floating point calculator here.


Edit:

Building on Khanal's answer, this link to Latitude/Longitude suggests that the numbers are indeed fixed point and explains the sign convention.

Perhaps more useful for the calculations is HexIt, which allows choosing from a variety of C data types, both integer and floating point, as well as flipping back and forth between little and big endian representations.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!