iOS Question Bit.ToBinaryString

schimanski

Well-Known Member
Licensed User
Longtime User
Is there something like

B4X:
Bit.ToBinaryString(Pruefsumme)

in B4i?
 

schimanski

Well-Known Member
Licensed User
Longtime User
:(Thanks for response. But is there no way to change a string or integer to a binary string? I have spend month before in my binary subs. It is the only thing i need, to use the complete subs in my new b4i-project.

P.S. I'm very enthusiastic about, how simple and fast b4i could be managed...
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can easily create such a method:
B4X:
Sub ToBinaryString(number As Int) As String
   Dim sb As StringBuilder
   sb.Initialize
   Dim x As Int = Bit.ShiftLeft(1, 31)
   For i = 0 To 31
     Dim ii As Int = Bit.AND(number, x)
     If ii <> 0 Then
       sb.Append("1")
     Else
       sb.Append("0")
     End If
     x = Bit.UnsignedShiftRight(x, 1)
   Next
   Return sb.ToString
End Sub
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
How to fix this then?

Sub LogByte(b As Byte)
Log(NumberFormat2(Bit.ToBinaryString(Bit.AND(0xff, b)), 8, 0, 0, False))
End Sub
 
Upvote 0
Top