I don't think I'm doing this correct but can anyone help me out trying to fix my code so it does work..
B4X:
Sub Display_num() As String
Dim myData As String
myData = "c000"
Dim myNumber As Int
myNumber = "16"
Dim Display As String
Display = ""
Dim intCounter As Int
Dim intBit As Int
If myData = 0 Then Return "display nothing"
intBit = 1
For intCounter = 1 To myNumber
If myData & intBit > 0 Then
Display = intCounter
If intCounter < myNumber Then Msgbox (Display, "show")
End If
intBit = intBit * 2
Next
End Sub
based on my example it should only display 2 message boxs:
Message1 = 7
Message2 = 8
Sub Activity_Create(FirstTime As Boolean)
Log(ConvertToInt("0100"))
Log(ConvertToInt("0200"))
Log(ConvertToInt("0080"))
End Sub
Sub ConvertToInt(h As String) As Int
Dim hex As Int
hex = Bit.ParseInt(h.SubString2(2, 4) & h.SubString2(0,2), 16)
Return Logarithm(hex, 2) + 1
End Sub
Isn't it 40+80=c0 ? I mean, why do you denote it as 4000 and 8000? And if so, when you write 0080, you mean 8000 in hex? when you write 0001, you mean 100 in hex?
Dim a As String
Dim b As String
Dim c As String
c=""
a="c0"
b=Bit.ToBinaryString (Bit.ParseInt(a,16))
For k=b.Length -1 To 0 Step-1
If b.CharAt (k)="1" Then c=c & (b.Length -k)
Next
Msgbox(c,"ok")
If for some reason, you wish to write c0 as c000, you should obviously replace