Results 1 to 2 of 2

Thread: Getting Binary values from text

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    8

    Getting Binary values from text

    Hi i know its a simple question but I have a textbox and i need to get the binary values from whatever is inputed into the box and the have the binary data be desplayed into another textbox.
    -=[ñít®ö]=-

  2. #2
    Member
    Join Date
    Sep 2001
    Location
    Fishburn
    Posts
    45
    I'm not 100% sure this is what you need, but the code below will convert a decimal integer value into binary. It assumes the decimal value is being entered in TextBox1, the result is put into TextBox2, executed from the click event of Button1.
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Try
                Dim Dec_Value As Long = CLng(TextBox1.Text)
                Dim Bin_Value As String = ""
                Dim Temp As Long
                Temp = 1
                Do Until Temp > Dec_Value
                    Temp = Temp * 2
                Loop
                Do Until Temp < 1
                    If Dec_Value >= Temp Then
                        Bin_Value &= "1"
                        Dec_Value -= Temp
                    ElseIf Bin_Value <> "" Then
                        Bin_Value &= "0"
                    End If
                    Temp = Temp / 2
                Loop
                TextBox2.Text = Bin_Value
            Catch
                MsgBox("Invalid input value entered")
            End Try
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width