Results 1 to 4 of 4

Thread: binary to Decinal and Hexidecimal

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    3

    Post

    Having big probs writing a vb program that converts a binary number to Decimal and Hexidecimal. if you can help let me know.

    Also could you tell me how to set the properties.

    Thanks.

    Sarah Jamerson

  2. #2
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    Can you give us more information? What translates it? Examples etc.

  3. #3
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145

    Post Working on it...

    I'll see what I can do.
    I've just done it on my calculator (Texas TI-83, you should all test to program it if you have one, it's great fun), so I can't imagine it'll be that hard (exept if you want very nice layout etc.).
    Stay tuned,
    Pentax
    Wilhelm Tunemyr,
    Swede in London

    [email protected]

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
    Heinrich Heine (1797-1856)

    Pravda vítezi!
    (Truth prevails!)

  4. #4
    Lively Member
    Join Date
    Mar 2000
    Posts
    82

    Post

    from programming vb6.0 - converts binary to dec
    then hex$(bintodec return value)

    Private Sub Command1_Click()
    Text2.Text = binToDec(Text1.Text)
    End Sub

    Public Function binToDec(value As String) As Long
    Dim result As Long, i As Integer, exponent As Integer

    For i = Len(value) To 1 Step -1
    Select Case Asc(Mid$(value, i, 1))
    Case 48
    Case 49
    result = result + power2(exponent)
    Case Else
    Err.Raise 5
    End Select
    exponent = exponent + 1
    Next
    binToDec = result

    End Function

    Public Function power2(ByVal exponent As Long) As Long
    Static result(0 To 31) As Long, i As Integer
    If result(0) = 0 Then
    result(0) = 1
    For i = 1 To 30
    result(i) = result(i - 1) * 2
    Next
    result(31) = &H80000000
    End If
    power2 = result(exponent)
    End Function

    hope it helps...
    oh and in case you need it - DecToBin

    Public Function decToBin(ByVal value As Long) As String
    Dim result As String, exponent As Integer
    result = String(32, "0")
    Do
    If value And power2(exponent) Then
    'bit is set - clear it
    Mid$(result, 32 - exponent, 1) = "1"
    value = value Xor power2(exponent)
    End If
    exponent = exponent + 1
    Loop While value

    result = Mid$(result, 33 - exponent)
    decToBin = result
    End Function

    Edited by _bman_ on 03-11-2000 at 11:18 AM

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