Android Question Change string to bit, then from bit to hex

Izmirov.Yaminovich

Member
Licensed User
Good day to all of you. I want to ask some question how to change a string of a coordination (latitude and longitude) to bit, then from bit to hex.

I'm use the below code to change from bit to hex then to int. This code is taught on this thread
http://www.b4x.com/android/forum/threads/string-manipulation-of-hex-string.49426/#post-308347

B4X:
Dim first, second As String
     Dim notsame As String
     notsame  = "same from above"
    msg = conv.HexFromBytes(buffer)
    msg2 = Regex.Split("FE1C",conv.HexFromBytes(buffer))
 
    Dim List1 As List
List1.Initialize
For Each row As String In msg2

If row.CompareTo(msg)= 0 Then
first = Null
Else
first = row
End If
Next

msg3 = Regex.Split("010121",first)

Dim List1 As List
List1.Initialize
For Each row1 As String In msg3
If row1.CompareTo(row)=0 Then
second = Null
Else

If row1.Length = 60 Then
second = row1

Dim data() As String
data=Regex.split("",second) 'take the 42BBD001 element
lat_hex=data(15)&data(16)&data(13)&data(14)&data(11)&data(12)&data(9)&data(10) 'reverse it
lon_hex=data(23)&data(24)&data(21)&data(22)&data(19)&data(20)&data(17)&data(18) 'reverse it
lat_temp = Bit.ParseInt(lat_hex, 16)
lon_temp = Bit.ParseInt(lon_hex, 16)
lat = lat_temp/10000000
lon = lon_temp/10000000
lbl_lat.Text = lat
lbl_lon.Text = lon

marker1.Remove
    marker1.IsInitialized
     marker1 = gmap.AddMarker(lbl_lat.Text, lbl_lon.Text, "Hello!!!")
      Dim cp As CameraPosition
      cp.Initialize(lbl_lat.Text, lbl_lon.Text, 20)
      gmap.AnimateCamera(cp)
Else
second = Null
End If
End If
Next
For the given code up there this is the log:

lat_hex = 152BCCAF lat_temp = 355191983 lat = 35.5191983
lon_hex = 505B109A lon_temp = 1348145306 lon = 134.8145306



now I need to convert the given coordinate in the Edittext1.text and Editext2.text

so that i can put in this string of hex than later i will change it to bit FE1C 19010121 6B800800 (Hex of Edittext1.text) (Hex of Editext2.text) DA010100 BAFFFFFF 00000000 01009A53 34DB

Is it by using conversion library, that change directly from the string (intToBytes method ) or is there any other alternative.?Or is it must go through the reverse process of the given code? Newbie programmer here. By using B4A, it have save a lot of time with the supportive forums member

Cheers
 
Last edited:
Top