December 1st, 2007, 07:28 PM
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.
December 1st, 2007, 09:38 PM
“Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
December 1st, 2007, 11:23 PM
Thanks for the help. I got it worked out. If you're interested this is the variation I got to work.
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)))
BinaryToDecimal = BinaryNum
Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
txtDecimalNum.Text = (BinaryToDecimal((txtBinaryNum.Text)))
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.
That's the same code that i want,thanks for sending this code.
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.
Originally Posted by ehbob23
Comments on this post