By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,330 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,330 IT Pros & Developers. It's quick & easy.

Hex to Float conversion of GPS Latitude

P: n/a

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

Nov 10 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a
On 10 Nov 2006 14:31:45 -0800, vo*****@hotmail.com wrote in
comp.lang.c:
>
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?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 11 '06 #2

P: n/a
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...

Nov 11 '06 #3

P: n/a
On 2006-11-11, vo*****@hotmail.com <vo*****@hotmail.comwrote:
>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...
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.)
Nov 11 '06 #4

P: n/a
vo*****@hotmail.com said:
>Did you have a question about the C language?

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.
Nov 11 '06 #5

P: n/a

vo*****@hotmail.com wrote:
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

Nov 11 '06 #6

P: n/a
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.
.... if I had a coder, ... but all I have is data:
http://sonyaexpress.com/track_log.jpg

Nov 11 '06 #7

P: n/a
In article <11**********************@h48g2000cwc.googlegroups .com>,
<vo*****@hotmail.comwrote:
>... 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.
--
If you lie to the compiler, it will get its revenge. -- Henry Spencer
Nov 11 '06 #8

P: n/a
In article <11**********************@h48g2000cwc.googlegroups .com>,
<vo*****@hotmail.comwrote:
>... 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/
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
Nov 11 '06 #9

P: n/a
vo*****@hotmail.com wrote:
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

Nov 12 '06 #10

P: n/a

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.

Nov 12 '06 #11

P: n/a

Ernie Wright wrote:
vo*****@hotmail.com wrote:
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?k...XtLnNXkT5oaQQg

- mkaras

Nov 12 '06 #12

P: n/a
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

Nov 12 '06 #13

P: n/a
Ernie Wright wrote:
vo*****@hotmail.com wrote:
>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;
}

--
Simon.
Nov 13 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.