Advertisement
LT1stSoloMID

二進制編碼系統

Nov 28th, 2015
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   Dim Min As Double = Val(TextBox1.Text) : Dim Max As Double = Val(TextBox2.Text)
  2.         Dim UnderInt As Integer = Val(TextBox3.Text) : Dim x As String = TextBox4.Text
  3.         If Check() = False Then MsgBox("輸入錯誤", 48, "Error") : Exit Sub
  4.         Dim DeCode As Long = (Max - Min) * 10 ^ UnderInt '編解碼所需要的值
  5.        Label5.Text = "Ans = "
  6.         If InStr(TextBox4.Text, ".") = 0 Then '二進制字串轉實數
  7.            For i = 1 To 99
  8.                 If 2 ^ i > DeCode Then
  9.                     Label5.Text &= Math.Round(Min + Convert.ToInt32(x, 2) * (Max - Min) / (2 ^ i - 1), UnderInt)
  10.                     Exit For
  11.                 End If
  12.             Next
  13.         Else '實數轉字串
  14.            For i = 1 To 99
  15.                 Dim Ans As Integer = (Val(x) - Min) / (Max - Min) * (2 ^ i - 1) '逆推
  16.                If 2 ^ i > DeCode Then Label5.Text &= Convert.ToString(Ans, 2) : Exit For
  17.             Next
  18.         End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement