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




Reply With Quote