Convert from HEX to decimal Latitude and Longitude

S

sazykin

I have a binary file with coordinates in Latitude and Longitude how can
I convert then to degrees?

Byte 180-183 (Latitude)
Hex 119c67 integer 18418791
Byte 184-187 (Longitude)
Hex 0fbe72 integer 16508674
Decoded Decimal: Latitude 30.697985
Longitude 27.514457
Any help please.
Thanx
 
R

Roland de Ruiter

I have a binary file with coordinates in Latitude and Longitude how can
I convert then to degrees?

Byte 180-183 (Latitude)
Hex 119c67 integer 18418791
Byte 184-187 (Longitude)
Hex 0fbe72 integer 16508674
Decoded Decimal: Latitude 30.697985
Longitude 27.514457
Any help please.
Thanx
Divide by 600000?
 
S

sazykin

Roland said:
Divide by 600000?


yeah!
but how to get integers when I use hex to integer :
System.out.println("Hex to Integer"+ Integer.valueOf("0fbe72",
16).intValue());
I'm getting - 1031794????
any ideas????
 
S

sazykin

yeah!
but how to get integers when I use hex to integer :
System.out.println("Hex to Integer"+ Integer.valueOf("0fbe72",
16).intValue());
I'm getting - 1031794????
any ideas????

or
String hexVal = "119C67";
System.out.println("Hex to Decimal. Hex = "+ hexVal + ",Decimal =
"+Integer.parseInt(hexVal,16));

I'm getting 1154151
?????
 
R

Roland de Ruiter

yeah!
but how to get integers when I use hex to integer :
System.out.println("Hex to Integer"+ Integer.valueOf("0fbe72",
16).intValue());
I'm getting - 1031794????
any ideas????
Are you sure you got the bytes right?
decimal 16508674 = hex 00FBE702 00 FB E7 02
decimal 18418791 = hex 01190C67 01 19 0C 67
 
L

Luc The Perverse

yeah!
but how to get integers when I use hex to integer :
System.out.println("Hex to Integer"+ Integer.valueOf("0fbe72",
16).intValue());
I'm getting - 1031794????
any ideas????

See the example here.

http://mindprod.com/jgloss/hex.html

However - even if that functionality were not built in, parsing a hex number
should be trivial with a simple for loop. Perhaps you should write it for
practice.

Something like this perhaps :) (note - I have not compiled or tested this)

int parseHex(String x){
int ret = 0;
for(char c : x.toCharArray()){
ret*=16;
if(c>='a'&&c<='f')
ret+=c-'a'+10;
if(c>='A'&&c<='F')
ret+=c-'A'+10;
if(c>='0'&&c<='9')
ret+=c-'0';
else
return 0; //error handling?
}
return ret;
}
 

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,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top