用二进制读取文件,存到一个byte型的字节数组buf()中。
然后一个一个字节读取其ascii码,并将此数字转成十六进制。 hex( asc( buf(i) ) )
将所有字节对应的十六进制字母连成一个字符串 ,就像 AE9C7A5D54F6A……
要还原的时候,取2位符,转为10进制数字,再存回一个字节数组,全部转完后写入一个文件,就行了。
补充:可能是我说用chrb()误导了你,抱歉。直接存入byte型的数组就行了,不需要chrb转成字符串的。
想做到是没什么难度的,只是感觉毫无意义。
————————————————————
得~ 楼主执着成这样,给你一段代码:
Sub FileToChr01(SFile As String, TFile As String)
Dim B As Byte, S As String
Dim I As Integer
Open SFile For Binary Access Read As #1
Open TFile For Binary Access Write As #2
Do While Not EOF(1)
Get #1, , B
S = ""
For I = 7 To 0 Step -1
S = S & IIf((B And (2 ^ I)) > 0, "1", "0")
Next I
Put #2, , S
Loop
Close #2
Close #1
End Sub
Sub Chr01ToFile(SFile As String, TFile As String)
Dim B As Byte, N As Byte
Dim P As Integer
Open SFile For Binary Access Read As #1
Open TFile For Binary Access Write As #2
P = 0: N = 0
Do While Not EOF(1)
Get #1, , B
P = P + 1
N = N * 2 + IIf(B = Asc("1"), 1, 0)
If P = 8 Then
Put #2, , N
P = 0: N = 0
End If
Loop
Close #2
Close #1
End Sub
Private Sub Command1_Click()
FileToChr01 "C:\1.txt", "C:\2.txt"
Chr01ToFile "C:\2.txt", "C:\3.txt"
End Sub
一、文件在硬盘信息太多,你需要什么信息?内容?存储信息?
二、“读取到记事本中(就是变成一堆零和一)”没有理解错的话,你要存储为二进制文件?
三、“之后再把这些零和一还原成文件”还原成什么文件?还原成十进制的记事本文件?