# Converting hex value to lat/long

Sorry if this is the wrong place to ask this but I'm stumped. I'm looking at iOS code as follows.

``````- (NSString *)currentE6Location {
CLLocationCoordinate2D loc = [AppDelegate instance].mapView.centerCoordinate;
return [NSString stringWithFormat:@"%08x,%08x", (int)(loc.latitude*1E6), (int)(loc.longitude*1E6)];
}
``````

So it's pretty simple.. From my understanding is they are taking a lat/lon and changing it from a float to an int then converting the int to a hex that is 0 padded in the front. So the hex value is 8 chars in length. The issue I'm having is do the same thing in python..

So the iOS app sends hex values like

``````36.968772,-122.013498   "0234194f,f8ba38ae"
``````

The first set are lat/long and the 2nd are roughly their hex values

The lat works just fine

``````0234194f = 36968783
``````

So 36968783 / 1e6 = 36.968783 (like I said its a rough estimate between the two)

But the 2nd one is odd

``````f8ba38ae = 4172953774
``````

The seem to use a 4 there if it's a - value for lon since you can't have a negative int has a hex value. So dropping the 4

``````172953774 / 1e6 = 172.953774 (so knowing the 4 is there it would be -172.953774)
``````

So I'm a bit stumped on why it works fine for the lat but not the lon..

Again sorry if this is the wrong site for this.. please close if it is.

I'm not sure that this is the right place -- StackOverflow would have been a fine place to ask -- but I'll answer anyway. Essentially the issue is that `%x` treats the argument as an unsigned int. So the value `f8ba38ae` is the two's complement representation of the original signed int.
``````>>> import struct