Hex to Float conversion of GPS Latitude

V

volosov

I would really appreciate if someone could give me a hint
how these floats are encoded:

0B7D2F70 41.8713
0B7D232F 41.8687
0B7D220F 41.8684

Thanks in advance

Vadim
 
J

Jack Klein

I would really appreciate if someone could give me a hint
how these floats are encoded:

0B7D2F70 41.8713
0B7D232F 41.8687
0B7D220F 41.8684

Thanks in advance

Vadim

Did you have a question about the C language?
 
V

volosov

Did you have a question about the C language?

I can teach C :)

.... just thought C-people are the most qualified for my question (since
the population of Assembler-people sharply diminished)
Someone just might find this question a brain-teaser and give it a
try...
 
A

Andrew Poelstra

I can teach C :)

... just thought C-people are the most qualified for my question (since
the population of Assembler-people sharply diminished)
Someone just might find this question a brain-teaser and give it a
try...

The folks at sci.crypt would be better suited to decoding. They
hate "brainteasers" like this though, so you might not have such
great luck. (The fact that it's pretty well-defined, unlike
"decode XXXXXXXXXXXXXX into a common saying", will likely help
you.)
 
R

Richard Heathfield

(e-mail address removed) said:
I can teach C :)

Oh, so it's *your* fault, is it? Come over here a minute...

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
 
M

mkaras

I would really appreciate if someone could give me a hint
how these floats are encoded:

0B7D2F70 41.8713
0B7D232F 41.8687
0B7D220F 41.8684

Thanks in advance

Vadim

You should look at test cases using numbers such as:
0.0
1.0
2.0
4.0
8.0
32767.0
10
100
1000
10000
and the pattern of encoding in the 4-bytes should become apparent.

- mkaras
 
W

Walter Roberson

... if I had a coder, ... but all I have is data:
http://sonyaexpress.com/track_log.jpg

Based upon that data, it appears that the GPS encoding is linear.
The top bit in each byte pair is not used for some reason, so
form a number as ((first hex byte pair * 2^16 / 2) + second hex byte pair).
A change of 120 (decimal) in that number represents a change of .0001
degree.

The encoding appears to be 2's complement (a smaller hex longitude is
more negative decimal). My guess is that 7FFF7FFF would encode the
least negative number, (-1/(120*1000)) degree, and that either
4000000 or 4000001 would encode the most negative, 1/(120*1000) more than
-180 degree.

I have not worked out the conversion to absolute coordinates, just
the relative changes.

The key entries to look at are #1 and #18: #1 is the most north-east
and #18 is the most south-west. That gives you the longest baseline
for finding the relative change between hex and decimal.

There is some uncertainty in the 120 figure, by about +/- 0.1
which is close enough to say "It wouldn't make any sense for them
to encode in multiples of 119.82 thousands of a degree" and so
Occamize the figure to 120 exactly.
 
W

Walter Roberson

... if I had a coder, ... but all I have is data:
http://sonyaexpress.com/track_log.jpg

If you go to the page above that one and look down to the last link,
you will see "Powered by Ontime Mobile". If you click on that,
the page that brings up indicates that OnTime Mobile
"Runs on all GPS-enabled Nextel/Motorola phones"

Reading around a bit, it appears there are literally dozens of different
GPS file formats in use. If you chase documentation for the Motorola
iDen line with GPS, you might be able to hunt down something relevant.

It is possible, though, that the file format in use is proprietary:
they could be calculating the locations based upon the GPS data and
storing those in their own private format.

I looked around a bit but did not manage to dig out the relevant
information out of (too many) pages. I did find a large resource
sight that has too many links for me to read through at this time:
http://gpsinformation.net/
 
E

Ernie Wright

I would really appreciate if someone could give me a hint
how these floats are encoded:

0B7D2F70 41.8713
0B7D232F 41.8687
0B7D220F 41.8684

http://sonyaexpress.com/track_log.jpg

The high bit in each byte is unused. Removing these four bits and
splicing together the remaining bits produces a 28-bit integer equal to
the number of degrees * 600000. Negative values are represented using
two's complement.

If code[] contains the four bytes in left to right order,

c = code[ 0 ] << 21 |
code[ 1 ] << 14 |
code[ 2 ] << 7 |
code[ 3 ];
if ( c & 0x8000000 )
c -= 0x10000000;
degrees = c / 600000.0;

- Ernie http://home.comcast.net/~erniew
 
V

volosov

Walter,

Thank You very much for trying to solve this riddle.
I am a founder of OnTime Mobile. But this track log is unrelated to the
core business of the company. I'm experimenting with GPS data logger
and that's how it stores data.
 
M

mkaras

Ernie said:
I would really appreciate if someone could give me a hint
how these floats are encoded:

0B7D2F70 41.8713
0B7D232F 41.8687
0B7D220F 41.8684

http://sonyaexpress.com/track_log.jpg

The high bit in each byte is unused. Removing these four bits and
splicing together the remaining bits produces a 28-bit integer equal to
the number of degrees * 600000. Negative values are represented using
two's complement.

If code[] contains the four bytes in left to right order,

c = code[ 0 ] << 21 |
code[ 1 ] << 14 |
code[ 2 ] << 7 |
code[ 3 ];
if ( c & 0x8000000 )
c -= 0x10000000;
degrees = c / 600000.0;

- Ernie http://home.comcast.net/~erniew

You can see the above ideas implemented at:

http://spreadsheets.google.com/ccc?key=pOlShElzBXtLnNXkT5oaQQg

- mkaras
 
V

volosov

Ernie, mkaras

You guys are amazing... :)
Thank you very much.

Thanks a lot to all who spent time thinking about it.

I really appreciate it.

As I said in the beginning of the thread: C-people rule!

I also posted this question on sat-nav, math and crypt forums, and
C-people, ... I said it already :)

Case is closed!

Cheers
 
S

Simon Biber

Ernie said:
I would really appreciate if someone could give me a hint
how these floats are encoded:

0B7D2F70 41.8713
0B7D232F 41.8687
0B7D220F 41.8684

http://sonyaexpress.com/track_log.jpg

The high bit in each byte is unused. Removing these four bits and
splicing together the remaining bits produces a 28-bit integer equal to
the number of degrees * 600000. Negative values are represented using
two's complement.

If code[] contains the four bytes in left to right order,

c = code[ 0 ] << 21 |
code[ 1 ] << 14 |
code[ 2 ] << 7 |
code[ 3 ];
if ( c & 0x8000000 )
c -= 0x10000000;
degrees = c / 600000.0;

Very good. Here's another formulation:

#include <stdio.h>

float val(unsigned long x)
{
unsigned long b = (((x >> 24) & 0x7F) << 21)
| (((x >> 16) & 0x7F) << 14)
| (((x >> 8) & 0x7F) << 7)
| (x & 0x7F);
if (b & 0x8000000) b -= 0x10000000;
return b / 600000.0;
}

int main(void)
{
printf("%.4f\n", val(0x0B7D2F70));
printf("%.4f\n", val(0x0B7D232F));
printf("%.4f\n", val(0x0B7D220F));
return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top