Community discussion forum

Binary to Decimal Convertor

This is a comment thread discussing Binary to Decimal Convertor
  • 9 years ago

    This thread is for discussions of Binary to Decimal Convertor.

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 5 years ago

    x isn't defined as local so might cause a problem if you had a global variable called x.


    How about a recursive definition?


    If the binary number string to be converted is "" then
     the value is 0
    else
     the value is 2 * binaryTohexadecimal(all but the last character of the string) + decimal value of the last character in the string
    endif


    Code:
    Function BinToHex(bits As String) As Long
    If (bits = "") Then
       BinToHex = 0
    Else
       BinToHex = 2 * BinToHex(Left(bits, Len(bits) - 1)) + CLng(Right(bits, 1))
    End If
    End Function


    If you're prepared to accept that function return values in VB are automatically initialised to zero unless altered then


    Code:
    Function BinToHex(bits As String) As Long
    If (bits <> "") Then
       BinToHex = 2 * BinToHex(Left(bits, Len(bits) - 1)) + CLng(Right(bits, 1))
    End If
    End Function


    would work.


    Let's hear it for recursion!

  • 5 years ago

    I don't mean to offend you , but that is quite messy.....
    The Below code will offer you your Flexability and your Fast Execution
    The Fact is, I know more then i get paid to know.... I'll give it to you free anyway


    Public Function BinaryToDec(BinaryValue As String) As Long
    Do
    BinaryToDec = BinaryToDec + (Left(BinaryValue, 1) * 2 ^ (Len(BinaryValue) - 1))
    BinaryValue = Mid(BinaryValue, 2)
    Loop Until BinaryValue = ""
    End Function


  • 3 years ago

    please some one help me!!!!! i'm meant to creat a calculator that can add subtract, multiply and divide and gives the answer in Decimal....


    in Visual Basic! i have no idea on how to go about this!....i've already created the interface but the rest????? i don' got a clue!

Post a reply

Enter your message below

Sign in or Join us (it's free).