convert number base 10 to base 2
convert number base 10 to base 2
Rate convert number base 10 to base 2
(2(2 Vote))
If TextBox1.Text = "" Then Exit Sub
Dim i As Integer = TextBox1.Text
Dim idigit As Integer
Dim str As String = String.Empty
Dim i2 As Integer = 2
Dim x As Integer
For x = 0 To 100
If 2 ^ x >= i Then
i2 = x
Exit For
End If
Next
Dim t = i2
While t >= 0
str &= getPosition(t, i)
t -= 1
End While
Dim s As String = Microsoft.VisualBasic.Right(str, i2 + 1)
Dim v As String
If Mid(s, 1, 1) = 0 Then
v = Mid(s, 2)
Else
v = s
End If
TextBox2.Text = v
End Sub
Private Function getPosition(ByVal i As Integer, ByRef ivalue As Integer) As String
Try
If 2 ^ i <= ivalue Then
getPosition = "1"
ivalue -= 2 ^ i
Else
getPosition = "0"
End If
Catch ex As Exception
End Try
End Function
convert number base 10 to base 2 Comments
No comments yet — be the first to post one!
Post a Comment