B4J Question Convert String to hexadecimal to get Chr()

Pedro Caldeira

Active Member
Licensed User
Longtime User
I know its a noob question, but how can I get the Chr() of a number in Hexadecimal
I have the number as a string, in the first place.
I have the string "313735" and I need to get the:

B4X:
Chr(0x31) & Chr(0x37) & Chr(0x35)
 

stevel05

Expert
Licensed User
Longtime User
Something like this
B4X:
    Dim Str As String = "313735"
  
    Dim AscVal(3) As Int
  
    For i = 0 To 2
        AscVal(i) = Bit.ParseInt(Str.SubString2(i * 2, i * 2 + 2),16)
    Next
  
    For i = 0 To AscVal.Length - 1
        Log(Chr(AscVal(i)))
    Next
t

B4x will automatically convert (Valid) numeric strings to a number.
 
Last edited:
Upvote 0

Knoppi

Active Member
Licensed User
Longtime User
here a solution without any lib
B4X:
Dim hex As String = "313735"
For i=0 To hex.Length -1 Step 2
    'Log( Chr( hex.SubString2( i, i+2)))
    Log( Chr( Bit.ParseInt( hex.SubString2( i, i+2), 16)))
Next

edit: sorry is a decimal sulution
edit2: now with hex
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Updated answer with hex conversion
 
Upvote 0
Top