問題很簡單,但答案應該是非我能力所及的...
--------------------------------------------------------------------------------------
c:\test.txt <<--純文字資料
按下<按鈕1>會執行把 c:\test.txt 檔轉成二進碼資料
存入 c:\a.txt
按下<按鈕2>會執行把 c:\a.txt 檔由二進碼->原始資料
並存入 c:\b.txt
&如果可以轉為16進碼更好~
-------------------------------------------------------------------------------------
PS. 答案完整(經測試)+快速的好心人 敝人親自獻上20點
<100%>不交付投票!!
2006-12-12 14:26:54 · 1 個解答 · 發問者 ¦Ü¨} ª 5 in 電腦與網際網路 ➔ 程式設計
回答者: JJ ( 初學者 4 級 )
你所給的程式碼好像有些問題?
因為經過測試,可以順利把資料存成2進碼 和存成16進碼
但是!讀取2編碼和16編碼回存原資料時c:\test.txt
卻變成亂碼 ="= 可以請你修改後,用WORD寄到
killman_xp@yahoo.com.tw 嗎?
知識 竟然無法顯示 左斜(左上 右底)和右斜(左底 右上),真是怪異...
2006-12-15 12:19:02 · update #1
Public Function C102(a As Integer) As String
Dim q As Integer, r As Integer
C102 = ""
q = a
While (q > 1)
r=q Mod 2
q=q \ 2
C102= r & C102
Wend
C102 = Right("0000000" & q & C102, 8)
End Function
Public Function C210(a As String) As String
Dim i As Integer, r As Integer
r = Val(Left(a, 1))
For i = 2 To 8
r = r * 2 + Val(Mid(a, i, 1))
Next i
C210 = Chr(r)
End Function
Public Function C1016(a As Integer) As String
Dim q As Integer, r As Integer
r= a Mod 16
q= a \ 16
If (r > 9) Then
C1016 = Chr(55 + r)
Else
C1016 = r
End If
If (q > 9) Then
C1016 = Chr(55 + q) & C1016
Else
C1016 = q & C1016
End If
End Function
Public Function C1610(a As String) As String
Dim l As Integer, r As Integer
Dim i As Integer
r = Asc(Right(a, 1))
l = Asc(Left(a, 1))
If (l > 57) Then
i = l - 55
Else
i = l - 48
End If
If (r > 57) Then
i = i * 16 + r - 55
Else
i = i * 16 + r - 48
End If
C1610 = Chr(i)
End Function
Private Sub Command1016_Click()
Dim i As Integer, a As Integer, b As Integer
Dim buf As String, buf2 As String
Open "c:test.txt" For Input As #1
Open "c:a.txt" For Output As #2
Do While Not (EOF(1))
Line Input #1, buf
buf2 = ""
For i = 1 To Len(buf)
buf2 = buf2 & C1016(Asc(Mid(buf, i, 1)))
Next i
Print #2, buf2
Loop
Close #1
Close #2
MsgBox "Done."
End Sub
Private Sub Command102_Click()
Dim i As Integer, a As Integer, b As Integer
Dim buf As String, buf2 As String
Open "c:test.txt" For Input As #1
Open "c:a.txt" For Output As #2
Do While Not (EOF(1))
Line Input #1, buf
buf2 = ""
For i = 1 To Len(buf)
buf2 = buf2 & C102(Asc(Mid(buf, i, 1)))
Next i
Print #2, buf2
Loop
Close #1
Close #2
MsgBox "Done."
End Sub
Private Sub Command1610_Click()
Dim i As Integer, a As Integer, b As Integer
Dim buf As String, buf2 As String
Open "c:a.txt" For Input As #1
Open "c:test.txt" For Output As #2
Do While Not (EOF(1))
Line Input #1, buf
buf2 = ""
For i = 1 To Len(buf) Step 2
buf2 = buf2 & C1610((Mid(buf, i, 2)))
Next i
Print #2, buf2
Loop
Close #1
Close #2
MsgBox "Done."
End Sub
字太多了 後續 ...
2006-12-15 12:07:14 補充:
Private Sub Command210_Click()
Dim i As Integer, a As Integer, b As Integer
Dim buf As String, buf2 As String
Open "c:a.txt" For Input As #1
Open "c:test.txt" For Output As #2
2006-12-15 12:07:23 補充:
Do While Not (EOF(1))
Line Input #1, buf
buf2 = ""
For i = 1 To Len(buf) Step 8
buf2 = buf2 & C210((Mid(buf, i, 8)))
Next i
Print #2, buf2
Loop
Close #1
Close #2
MsgBox "Done."
End Sub
2006-12-15 07:06:38 · answer #1 · answered by JJ 7 · 0⤊ 0⤋