Created
October 28, 2015 20:52
-
-
Save heltonmarx/930944970cdde1d9af53 to your computer and use it in GitHub Desktop.
latitude longitude converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
float calculate(unsigned long x) | |
{ | |
float f; | |
float delta = 0.000277778; | |
unsigned long limit = 0x7FFFFFFF; | |
if (x < limit) { | |
f = (x * 0.01); | |
} else { | |
limit = 0xFFFFFFFF; | |
f = 0 - ((limit - x) * 0.01); | |
} | |
// return in arcsec to degree | |
return (f * delta); | |
} | |
/** | |
* Latitude = FF82AE23 (22.813769° S) 4286754339 | |
* 82129,5683998 (arcsec) | |
* | |
* Longitude = FEFD90EA (47.046461° W) 4278030570 | |
* 169367,2596 (arcsec) | |
*/ | |
int main(void) | |
{ | |
float latitude, longitude; | |
latitude = calculate(0xFF82AE23); | |
longitude = calculate(0xFEFD90EA); | |
if (latitude < 0) { | |
printf("latitude: %.4f S\n", (latitude * -1)); | |
} else { | |
printf("latitude: %.4f N\n", latitude); | |
} | |
if (latitude < 0) { | |
printf("longitude: %.4f W\n", (longitude * -1)); | |
} else { | |
printf("longitude: %.4f E\n", longitude); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment