Advertisement
ferraridriveby

Untitled

Sep 1st, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. Public Class frmMain
  2.  
  3. Private Sub btnConvert_Click(sender As Object, e As EventArgs) Handles btnConvert.Click
  4. 'Try
  5. ' Dim input As Integer = CInt(tbxInput.Text)
  6. ' Dim convert As String = Nothing
  7. ' For power As Integer = 8 To 0 Step -1
  8. ' If input >= 2 ^ power And input <> 0 Then
  9. ' input -= 2 ^ power
  10. ' convert += "1"
  11. ' ElseIf convert <> Nothing Then
  12. ' convert += "0"
  13. ' End If
  14. ' Next
  15. ' lblBinary.Text = convert
  16. 'Catch
  17. 'End Try
  18.  
  19. Try
  20. Dim input As Integer = CInt(tbxInput.Text)
  21. Dim convert As String = Nothing
  22. Dim div As Double = input
  23. Dim upto As Integer = Nothing
  24. Do While div >= 2
  25. div /= 2
  26. upto += 1
  27. Loop
  28. For power As Integer = upto To 0 Step -1
  29. If input >= 2 ^ power And input <> 0 Then
  30. input -= 2 ^ power
  31. convert += "1"
  32. Else 'If convert <> Nothing Then
  33. convert += "0"
  34. End If
  35. Next
  36. lblBinary.Text = convert
  37. Catch
  38. End Try
  39. End Sub
  40.  
  41. Private Sub btnConvert2_Click(sender As Object, e As EventArgs) Handles btnConvert2.Click
  42. Try
  43. Dim input As String = tbxInput2.Text
  44. 'input.Reverse()
  45. Dim Ainp() As String
  46. Dim convert As Integer = 0
  47.  
  48. For parts As Integer = 0 To input.Length - 1
  49. ReDim Preserve Ainp(parts + 1)
  50. Ainp(parts) = input(input.Length - 1 - parts)
  51. 'MessageBox.Show(Ainp(parts))
  52. convert += Ainp(parts) * (2 ^ parts)
  53. 'MessageBox.Show(convert.ToString)
  54. Next
  55.  
  56. lblDecimal.Text = convert
  57. Catch
  58. End Try
  59. End Sub
  60. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement