P Philip Prins Active Member Licensed User Longtime User Jan 12, 2021 #1 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. B4X: Copy 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
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. B4X: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Jan 12, 2021 #2 Code: Copy Dim bc As ByteConverter Dim b() As Byte = bc.HexToBytes("FFFFFFC8") Dim i() As Int = bc.IntsFromBytes(b) Log(i(0)) Upvote 0
Code: Copy Dim bc As ByteConverter Dim b() As Byte = bc.HexToBytes("FFFFFFC8") Dim i() As Int = bc.IntsFromBytes(b) Log(i(0))