Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Do Input #1, num Do y = num Mod 2 num = num \ 2 ans = y & ans Loop Until num = 0 ori = Len(ans) temp = Replace(ans, 1, "") If (ori - Len(temp)) Mod 2 = 0 Then ans = ans & "0" If (ori - Len(temp)) Mod 2 <> 0 Then ans = ans & "1" For i = Len(ans) To 1 Step -1 ansnum = ansnum + Val(Mid(ans, i, 1)) * (2 ^ (Len(ans) - i)) Next Print #2, ansnum: ansnum = 0: ans = "" Loop Until EOF(1) Close #2 Close #1 End End Sub
Dim x As Integer Dim ans As String Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Do While Not EOF(1) Input #1, x x = Val(x): ans = "" Do y = x Mod 2 x = x \ 2 ans = y & ans Loop Until x = 0 For i = Len(ans) + 1 To 7 ans = "0" & ans Next i If Right(ans, 1) = "1" Then ans = ans & "0" Else ans = ans & "1" s = 0: All = 0 For i = Len(ans) To 1 Step -1 All = All + (Val(Mid(ans, i, 1)) * 2 ^ s) s = s + 1 Next i Print #2, All Loop Close #2 Close #1 End End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do
Input #1, num
Do
y = num Mod 2
num = num \ 2
ans = y & ans
Loop Until num = 0
ori = Len(ans)
temp = Replace(ans, 1, "")
If (ori - Len(temp)) Mod 2 = 0 Then ans = ans & "0"
If (ori - Len(temp)) Mod 2 <> 0 Then ans = ans & "1"
For i = Len(ans) To 1 Step -1
ansnum = ansnum + Val(Mid(ans, i, 1)) * (2 ^ (Len(ans) - i))
Next
Print #2, ansnum: ansnum = 0: ans = ""
Loop Until EOF(1)
Close #2
Close #1
End
End Sub
Dim x As Integer
回覆刪除Dim ans As String
Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do While Not EOF(1)
Input #1, x
x = Val(x): ans = ""
Do
y = x Mod 2
x = x \ 2
ans = y & ans
Loop Until x = 0
For i = Len(ans) + 1 To 7
ans = "0" & ans
Next i
If Right(ans, 1) = "1" Then ans = ans & "0" Else ans = ans & "1"
s = 0: All = 0
For i = Len(ans) To 1 Step -1
All = All + (Val(Mid(ans, i, 1)) * 2 ^ s)
s = s + 1
Next i
Print #2, All
Loop
Close #2
Close #1
End
End Sub