We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

[3282] Binary to Decimal Convertor

Last post 03-31-2005 12:47 PM by breeze. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-01-1999 12:00 AM

    [3282] Binary to Decimal Convertor

    This thread is for discussions of Binary to Decimal Convertor.

    • Post Points: 0
  • 03-17-2003 7:23 PM In reply to

    • jstout
    • Not Ranked
    • Joined on 03-17-2003
    • New Member
    • Points 5

    BinaryToHexadecimal conversion

    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!
    • Post Points: 0
  • 05-28-2003 8:29 PM In reply to

    Say What?

    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

    • Post Points: 0
  • 03-31-2005 12:47 PM In reply to

    • breeze
    • Not Ranked
    • Joined on 03-31-2005
    • New Member
    • Points 5
    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 Points: 0
Page 1 of 1 (4 items)