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
Printable View
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
Can you give us more information? What translates it? Examples etc.
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
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