Android Question how to Convert HEX to normal character ?

hears

Active Member
Licensed User
Longtime User
Last edited:

hears

Active Member
Licensed User
Longtime User
Do you mean you have a string like "303132" and you want the chars for each couple, in this case "012"?
Mauro
yes ,303132 in normal string is 012
 
Upvote 0

hears

Active Member
Licensed User
Longtime User
thank you , i get many code like this :"6720706f6f6c20697320696e69746900"

serial device code alway in HEX format.
 

Attachments

  • 3333.png
    3333.png
    52.6 KB · Views: 220
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
I don't think you have to deal with hex format. This is only a way to show unprintable chars. You get bytes and you have to deal with them. You do a conversion which transforms bytes to hex. Display each byte and the work is done!
you string is "g pool is initi"
 
Last edited:
Upvote 0

hears

Active Member
Licensed User
Longtime User
Upvote 0

hears

Active Member
Licensed User
Longtime User
I don't think you have to deal with hex format. This is only a way to show unprintable chars. You get bytes and you have to deal with them. You do a conversion which transforms bytes to hex. Display each byte and the work is done!



i have directly use 'stringfrombytes()' didn't change data format to HEX.
the result is wrongbyteconverter_stringfrombytes..i think the format from WIFI ROUTER send is HEX format.so must first get HEX COED.after change again to normal character
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
i have directly use 'stringfrombytes()' didn't change data format to HEX.
the result is wrongbyteconverter_stringfrombytes..i think the format from WIFI ROUTER send is HEX format.so must first get HEX COED.after change again to normal character
OMG
It is not fun to help you! REALLY NOT.

READ the Documentation.

And try to understand what is happening with the different Methods!

the format from WIFI ROUTER send is HEX format
So you FIRST need to convert the HEX to Bytes. https://www.b4x.com/android/help/byteconverter.html#byteconverter_hextobytes
And then the Bytes to a String. https://www.b4x.com/android/help/byteconverter.html#byteconverter_stringfrombytes
 
Last edited:
Upvote 0

hears

Active Member
Licensed User
Longtime User
ok,now it is work now . StringFromBytes() must add "utf8"
B4X:
Dim hexs As String
        hexs="6720706f6f6c20697320696e69746900"
  
        Log(bc.StringFromBytes(bc.HexToBytes(hexs),"utf8"))

tomorrow i will try WIFI router ...I think directly use "StringFromBytes() " maybe work too.
 
Upvote 0
Top