Hex string to Int

Thanks Armoured for the tip!
do you know b4a function for binary to hex?
I have the vb6: hexbyte = bin2hex("10110010")
 
Upvote 0
i have created a sub routine to convert binary to decimal:

Code: Copy
Sub binTodec(binVal As String) As Int
Dim i As Int, v As Int, dec As Int 
i = binVal.Length
v = 1
For pos = i To 1 Step -1
    If binVal.SubString2(pos-1, pos) = "1" Then dec = dec + v
v = v * 2
Next 
Return dec
End Sub

then you can use:

Code: Copy
Bit.ToHexString(binTodec("10110010"))

or similar
 
Upvote 0
Thanks Armoured for the tip!
do you know b4a function for binary to hex?
I have the vb6: hexbyte = bin2hex("10110010")

I think you want this:
Code: Copy
Sub Bin2Hex(bnumber As String) As String
  Return Bit.ToHexString(Bit.ParseInt(bnumber,2))
End Sub

Then you can use:
Code: Copy
Dim hexbyte as String
hexbyte = Bin2Hex("10110010")
;)
 
Last edited:
Upvote 0
Nice :)
 
Upvote 0
Armoured,
Did you test the above sub? in my machine it is saying nonconvertible type.
didn't touch your code, but tried to put the returned string in an edittext.
Thanks in advance for more light on this.
 
Upvote 0
Armoured,
Did you test the above sub? in my machine it is saying nonconvertible type.
didn't touch your code, but tried to put the returned string in an edittext.
Thanks in advance for more light on this.

Yes I have tested my code but you can control for yourself with this:
Code: Copy
Msgbox("10110010 = " & Bin2Hex("10110010"),"Binary to Hex")
 

Attachments

  • Bin2Hex.png
    Bin2Hex.png
    14.2 KB · Views: 854
Last edited:
Upvote 0

Similar Threads

  • Question Question
Android Question Hex string to Int
Replies
4
Views
5K
  • Article Article
Android Code Snippet [B4X] Hex string to number
Replies
0
Views
6K
  • Locked
  • Article Article
Replies
6
Views
10K
Replies
9
Views
15K
Back
Top