Converting a Hex String to Binary?

Comalco

Member
Licensed User
Longtime User
Seems to be my night for asking questions......

I would like to step through a string of 23 characters and convert each character to its binary equivalent so I can check each byte's bits against a flag table.......

Has anyone got a sinple way of stepping through each byte in a string?

Many thanks........
 

mitsusdev

Member
Licensed User
Longtime User
Seems to be my night for asking questions......

I would like to step through a string of 23 characters and convert each character to its binary equivalent so I can check each byte's bits against a flag table.......

Has anyone got a sinple way of stepping through each byte in a string?

Many thanks........

Have you tried to use Basic4android - RandomAccessFile?

You can write (and read) single byte using a file for support.
 
Upvote 0

MLDev

Active Member
Licensed User
Longtime User
This code will step through each byte in hexString and convert hexString to a binary string binaryString.
B4X:
Dim binaryString As String = ""
Dim byteString As String
Dim zeros As String = "00000000"
   
If hexString.Length Mod 2 = 1 Then hexString = "0" & hexString
   
For i = 0 To hexString.Length - 1 Step 2
   byteString = Bit.ToBinaryString(Bit.ParseInt(hexString.SubString2(i, i+2), 16))
   byteString = zeros.SubString(byteString.Length) & byteString
   binaryString = binaryString & byteString
Next
 
Last edited:
Upvote 0
Top