Android Question Convertion to HEX

Baublanc

Member
Licensed User
Longtime User
I have 2 bytes let say 11 and 33 when i convert them with

a = ((Bit.ToHexString(11) & Bit.ToHexString(33)))

a= 1121

with 11 and 9

a = ((Bit.ToHexString(11) & Bit.ToHexString(9)))

a = 119 and not 1109

how to fix that.

Thanks
 

obscure

Member
Licensed User
Longtime User
Hey Baublanc!

Bit.ToHexString(11) is 11? Interesting!
Well, you could do the conversion with this tiny function:
B4X:
Sub dec2hex (inp As Int) As String
   Dim hex As List
   hex.Initialize
   hex.AddAll(Array As String("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"))
   If inp>255 Then
     inp=255
   End If
   Dim l As Int=inp/16
   Dim r As Int=inp Mod 16
   Return hex.Get(l)&hex.Get(r)
End Sub

Usage: Log(dec2hex(11)&dec2hex(9))
Output: 0B09
 
Upvote 0

Baublanc

Member
Licensed User
Longtime User
Thanks obscure (excuse me for the mistake ) and Erel, my exemple was not correct.

I have to pull the start adress from a controler and that's how i was doing it:

If job.Success = True Then
If job.GetString.SubString2(0,6) = "2,4,2," Then ' reponce = 2,4,2,3,9
AdrData = Bit.ParseInt(Bit.ToHexString(f(3)) & Bit.ToHexString(f(4)),16)​
end if​
end if

adrData=57 and not 777

so i change my code for:

If job.Success = True Then
If job.GetString.SubString2(0,6) = "2,4,2," Then ' reponce = 2,4,2,3,9
f = Regex.Split(",",job.GetString)
i = 0
B = 0
A = f(2)
v = 2
Do While (i < f(2))
v = v + 1
u = f(v)
B = B + Bit.ShiftLeft(u, (A - 1) * 8)
i = i + 1
A = A - 1
Loop
AdrData = B​
End if​
End If

adrData=777

Thanks again for you two
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…