Java Question Hex to String?

icakinser

Member
Licensed User
Longtime User
This is the JSON file I am working with:

B4X:
{"content": { "btitle":"Bob" "author":"Robert" "publisher":"sdfsdf" "other":"dsfsdf" "chapters":"1"
"chapter0": {
   "title":"bob"
   "content":"3C666F6E7420666163653D275365676F65205549272073697A653D2732273E73646673642066646E736473646620736D6A666C73646D6673203C623E6A6E666B6A6E736B6A6465667364666E202073646A666E6B6A7364666B6B64736D666B6C73646D666B6C6D6C736D6A736B6C6466203C2F623E646A6E6D666B6C6E736B6C64663C2F666F6E743E"

"chapter1": {
   "title":"toy"
   "content":"3C666F6E7420666163653D275365676F65205549272073697A653D2732273E6E646B6A666E6A736B646E667A7364662073646A666E6A736B646673643C2F666F6E743E"
}
}
}}

I can parse thru all the information and add the chapters to an list. I also put all the chapter contents into an array of strings and use the list index to show the contents in a web control. Can anyone tell me how to convert the hex in the contents property to a normal string?? I tried the bit.hex function but returns an error. Do I need to parse thru the string one at a time to get a result?
 

agraham

Expert
Licensed User
Longtime User
The "content" of content looks like it is ASCII coded characters. In that case using my ByteConverter library.

B4X:
   Dim content As String
   Dim bconv As ByteConverter
   Dim barray(0) As Byte
   content = "3C666F6E7420666163653D275365676F65205549272073697A653D2732273E6E646B6A666E6A736B646E667A7364662073646A666E6A736B646673643C2F666F6E743E"
   barray = bconv.HexToBytes(content)
   content = bconv.StringFromBytes(barray, "ASCII")
   Msgbox(content, "Content")
If they are another encoding, maybe UTF8 then use that in StringFromBytes. The strings for supported encodings can be obtained from bconv.SupportedEncodings.
 

icakinser

Member
Licensed User
Longtime User
THANK YOU! I forgot about your library :( I downloaded it before just never got around to installing it. Best of wishes!:)
 

Felix Maria

Member
Licensed User
Longtime User
Hi Agraham,
Hats off to your wonderful ByteConverter Library. It made my coding very simple reading from a bluetooth RFID card reader.

The Hex Output from the lib is "AAFF40000C36F375" .
It should be converted to string with the value of "0000800499" which is the actual value
from the card.
I tried using all the methods but invain.
Which method of the lib would do so?

Please advice!

In Dotnet the following code does the job
B4X:
        private void condec(string hd )
    {
            String hexString = hd;
            hexString = hexString.Replace(" ", "");
            hexString = hexString.Substring(6, 8);
            String result = "" + Convert.ToInt64(hexString, 16);
            while (result.Length < 10)
                result = "0" + result;
            MessageBox.Show( result);
    }

what is the equivalent of Convert.ToInt64(hexString, 16) ?

Thank You.

Maria.
 

Similar Threads

Top