A Armoured Member Licensed User Longtime User Dec 13, 2012 #1 Hi, In Java I can write: Code: Copy String hex = "2A" int intValue = Integer.parseInt(hex, 16); And in Basic4Android?
Hi, In Java I can write: Code: Copy String hex = "2A" int intValue = Integer.parseInt(hex, 16); And in Basic4Android?
A Armoured Member Licensed User Longtime User Dec 13, 2012 #2 Answer: Code: Copy dim hex as String dim intValue as Int hex = "2A" intValue = Bit.ParseInt(hex, 16); Upvote 0
Answer: Code: Copy dim hex as String dim intValue as Int hex = "2A" intValue = Bit.ParseInt(hex, 16);
Beja Expert Licensed User Longtime User Dec 13, 2012 #3 Thanks Armoured for the tip! do you know b4a function for binary to hex? I have the vb6: hexbyte = bin2hex("10110010") Upvote 0
Thanks Armoured for the tip! do you know b4a function for binary to hex? I have the vb6: hexbyte = bin2hex("10110010")
Stulish Active Member Licensed User Longtime User Dec 13, 2012 #4 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
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
A Armoured Member Licensed User Longtime User Dec 13, 2012 #5 Beja said: Thanks Armoured for the tip! do you know b4a function for binary to hex? I have the vb6: hexbyte = bin2hex("10110010") Click to expand... 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: Dec 13, 2012 Upvote 0
Beja said: Thanks Armoured for the tip! do you know b4a function for binary to hex? I have the vb6: hexbyte = bin2hex("10110010") Click to expand... 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")
Beja Expert Licensed User Longtime User Dec 13, 2012 #7 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.
A Armoured Member Licensed User Longtime User Dec 14, 2012 #8 Beja said: 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. Click to expand... 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 14.2 KB · Views: 854 Last edited: Dec 14, 2012 Upvote 0
Beja said: 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. Click to expand... Yes I have tested my code but you can control for yourself with this: Code: Copy Msgbox("10110010 = " & Bin2Hex("10110010"),"Binary to Hex")
Beja Expert Licensed User Longtime User Dec 14, 2012 #9 Yes Armoured, that was my mistake. Thanks so much Upvote 0