#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2007
    Posts
    4
    Rep Power
    0

    Convert Binary to Decimal in VB


    I've been looking for a way to do this for about two weeks now. Searching Google, Yahoo and even these forums. My question is. How can you convert Binary to Decimal? The app I am writing needs to take a binary number that someone enters into a text box, convert it to decimal and output that to another text box. This would be done with a button click event of course. I've got everything together except that part. I'm using Visual Studio 2005. Any help would be appreciated.
  2. #2
  3. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2007
    Posts
    4
    Rep Power
    0
    Thanks for the help. I got it worked out. If you're interested this is the variation I got to work.

    Code:
    Public Function BinaryToDecimal(ByRef Binary As String) As Integer
            Dim BinaryNum As Integer
            Dim BitCount As Short
    
            For BitCount = 1 To Len(Binary)
                BinaryNum = BinaryNum + (CDbl(Mid(Binary, Len(Binary) - BitCount + 1, 1)) * (2 ^ (BitCount - 1)))
            Next BitCount
            BinaryToDecimal = BinaryNum
    
        End Function
    
        Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
            txtDecimalNum.Text = (BinaryToDecimal((txtBinaryNum.Text)))
    
        End Sub
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    1
    Rep Power
    0

    thanks for this post


    This is the same code I needed in my Loan Thesis. Thanks for the one who posted this code..I've been having big troubles in finding ways to solve the same problem with for next loop, i think this could help.

    thanks.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    12
    Rep Power
    0

    GiffordBruno


    That's the same code that i want,thanks for sending this code.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0
    Hello all,
    I'm new to this site but I'm not new to the world. Here is something for all of you students to think about. If you are working on some type of school assignment and you use the code that someone else has written for you. You are facing failing the course and being expelled from school. You can also be facing federal criminal charges and be required to return any and all student aid. The federal government is very strict about this and they do prosecute. I just though that you should all know about the consequences for plagiarism. You can use the code to get some ideas about how to proceed but if you use the code out right you are in serious trouble. There are a lot of professors that go on these sites looking for this kind of cheating and it is cheating. When I was in school I know of a girl from China who did this. She wasn't prosecuted but she was deported. The last that I heard the Chinese government put her and her whole family in a Chinese prison. Is it really worth it. Design your own code and ask for help with it but don't ask others to write the code for you. Just a friendly warning.
    Thanks,
    rich!

    Originally Posted by ehbob23
    This is the same code I needed in my Loan Thesis. Thanks for the one who posted this code..I've been having big troubles in finding ways to solve the same problem with for next loop, i think this could help.

    thanks.

    Comments on this post

    • medialint disagrees : But in the real world I borrow code all the time to solve a part of a bigger problem. I do tend to agree but if the thesis (two years ago) was five lines of code ... well ...

IMN logo majestic logo threadwatch logo seochat tools logo