Results 1 to 21 of 21

Thread: [RESOLVED] Denary (Base 10) to Binary (Base 2)

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Location
    Rotherham,UK
    Posts
    26

    Resolved [RESOLVED] Denary (Base 10) to Binary (Base 2)

    i am trying to convert Denary numbers to a binary value, using two's compliments, but the i am using is coming back wrong. any help will be greatly apreciated.

    Code:
    Option Explicit
    Public Function InputNumber(Numpass As Double) As String
    Dim Bintemp As String
        While Numpass >= 0 'while number is greater or equal to 1
            Bintemp = Bintemp & Numpass Mod 2 'Divides by 2 each time and collects the remainder
                If OddEven(Numpass) = True Then
                    Bintemp = Bintemp & "0"
                Else
                    Bintemp = Bintemp & "1"
                End If
          Numpass = (Numpass / 2)
          Wend
    InputNumber = Bintemp
    End Function
    Public Function OddEven(num As Integer) As Boolean 'true of false
        If num Mod 2 = 0 Then
            OddEven = True 'Even
        Else
            OddEven = False 'False
        End If
    End Function
    Public Sub Calculate()
    Dim StrBinary As String, temp As Integer
        If Form1.OptBinary.Value = True Then
            temp = Form1.txtNumber.Text
            StrBinary = StrReverse(InputNumber(temp))
            Form1.txtAnswer.Text = StrBinary
        End If
        If Form1.OptOctal.Value = True Then
            temp = Form1.txtNumber.Text
            StrBinary = Oct(temp)
            Form1.txtAnswer.Text = StrBinary
        End If
        If Form1.OptDenary.Value = True Then
            temp = Form1.txtNumber.Text
            StrBinary = temp
            Form1.txtAnswer.Text = StrBinary
        End If
        If Form1.OptHexidecimal.Value = True Then
            temp = Form1.txtNumber.Text
            StrBinary = Hex(temp)
            Form1.txtAnswer.Text = StrBinary
        End If
        
    End Sub
    Last edited by frozenpost; Jun 1st, 2007 at 10:59 AM.
    thanks Frozenpost

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