Hello ,
I have a hex string that needs to be converted .
If longitude is in west or latitude in south, multiply result by –1. To determine if the coordinate is negative,
convert it to binary format and check the very first bit. If it is 0, coordinate is positive, if it is 1, coordinate is
negative.
Example:
Received value: 20 9c ca 80
Converted to BIN: 00100000 10011100 11001010 10000000 first bit is 0, which means coordinate is positive
Convered to DEC: 547146368
For more information see two‘s compliment arithmetics.
This works when the longitude is positive , how to convert when it is negative?
Thanks in advance ,
Philip
I have a hex string that needs to be converted .
If longitude is in west or latitude in south, multiply result by –1. To determine if the coordinate is negative,
convert it to binary format and check the very first bit. If it is 0, coordinate is positive, if it is 1, coordinate is
negative.
Example:
Received value: 20 9c ca 80
Converted to BIN: 00100000 10011100 11001010 10000000 first bit is 0, which means coordinate is positive
Convered to DEC: 547146368
For more information see two‘s compliment arithmetics.
B4X:
Dim Longitude As String = HxStr.SubString2(68,76)
Dim Latitude As String = HxStr.SubString2(76,84)
Latitude = Bit.ParseInt(Latitude,16)
Longitude = Bit.ParseInt(Longitude,16)
This works when the longitude is positive , how to convert when it is negative?
Thanks in advance ,
Philip