views:

65

answers:

3

Given:

  • 0x12E7 represents 48°39'
  • 0x3026 represents 123°26'

What is the most efficient way to convert the representation of those latitudes into two variables:

  • hours
  • minutes

Where the first example would be:

  • hours = 48
  • minutes = 39

And the second example:

  • hours = 123
  • minutes = 26

Edit

Latitude is an int.

+1  A: 

If you have a String value:

int i = Integer.parseInt("12E7", 16);
int hours = i / 100;
int minutes = i % 100;

Or you can use the 0x... format directly:

int i = 0x12E7;
int hours = i / 100;
int minutes = i % 100;
cletus
If you remove `0x` from the String in `Integer#parseInt()`, it will work as expected.
BalusC
+1  A: 
hours = 0x12E7 / 100;
minutes = 0x12E7 % 100;
WhirlWind
+1  A: 
int l = 0x12E7;
int h = l / 100;
int m = l % 100;
System.out.printf("%d°%d'", h, m); // 48°39'
BalusC
Thank you for this.
Dave Jarvis