如何把文件转换成十六进制的格式?

kwxx 2002-03-17 08:09:21
把任意一个文件转换成十六进制的格式,就象UE那样,而且速度要快,什么7K的文件要转2、30秒的程序就算了。谁的最快就给谁分。谢了!
...全文
137 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
kwxx 2002-03-20
  • 打赏
  • 举报
回复
128DDR打开2M的文件没问题吧?
我马上就给分!
xxlroad 2002-03-17
  • 打赏
  • 举报
回复
zyl910 2002-03-17
  • 打赏
  • 举报
回复
只不过不要打开太大的文件(1M以上),因为它是把整个文件读取到内存再处理的,估计占用内存的空间是文件的12倍(3[两个16进值数+一个空格] * 2[UniCode字符占两个字节] * 2[一个是读取的、一个是处理的])!
zyl910 2002-03-17
  • 打赏
  • 举报
回复
我这段时间在思考最快的算法!

给你看看最新的代码:

ZHexView.vbp
====================================================================
Type=Exe
Form=FrmZHexView.frm
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\..\WINDOWS\SYSTEM\stdole2.tlb#OLE Automation
Object={3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0; RICHTX32.OCX
Object={F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0; COMDLG32.OCX
IconForm="FrmZHexView"
Startup="FrmZHexView"
ExeName32="ZHexView.exe"
Command32=""
Name="HexView"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="910"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1




FrmZHexView.frm
====================================================================
VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form FrmZHexView
Caption = "ZHexView"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
LockControls = -1 'True
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin MSComDlg.CommonDialog CDlg1
Left = 2100
Top = 1350
_ExtentX = 847
_ExtentY = 847
_Version = 393216
CancelError = -1 'True
End
Begin RichTextLib.RichTextBox RText1
Height = 1245
Left = 0
TabIndex = 2
Top = 330
Width = 2115
_ExtentX = 3731
_ExtentY = 2196
_Version = 393217
HideSelection = 0 'False
ScrollBars = 3
DisableNoScroll = -1 'True
RightMargin = 1e7
TextRTF = $"FrmZHexView.frx":0000
End
Begin VB.TextBox TxtFile
Height = 285
Left = 570
TabIndex = 1
Text = "Text1"
ToolTipText = "文件名"
Top = 0
Width = 4035
End
Begin VB.Label Lbl1
AutoSize = -1 'True
Caption = "打开:"
Height = 180
Left = 30
TabIndex = 0
Top = 30
Width = 540
End
End
Attribute VB_Name = "FrmZHexView"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Const MeText = "ZHexView"

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function timeGetTime Lib "winmm.dll" () As Long

Private Sub Form_Load()
'Dim S1 As String, S2 As String * 3
'
'S1 = Space$(3)
'S2 = "03 "
'Call CopyMemory(ByVal StrPtr(S1), ByVal StrPtr(S2), 6)
'
'Debug.Print S1

CDlg1.Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly
CDlg1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"

End Sub

Private Sub Form_Resize()
If Me.WindowState = 1 Then Exit Sub

On Error Resume Next

TxtFile.Width = Me.ScaleWidth - TxtFile.Left
RText1.Width = Me.ScaleWidth
RText1.Height = Me.ScaleHeight - RText1.Top

On Error GoTo 0

End Sub

Private Sub Lbl1_Click()
'
End Sub

Private Sub Lbl1_DblClick()
On Error GoTo ErrOpen

CDlg1.ShowOpen
TxtFile.Text = CDlg1.FileName
TxtFile_KeyPress vbKeyReturn

On Error GoTo 0

Exit Sub

ErrOpen:
On Error GoTo 0

End Sub

Private Sub TxtFile_Change()
'
End Sub

Private Sub TxtFile_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
LoadHex TxtFile.Text
End If

End Sub

Private Sub LoadHex(FileStr As String)
Dim LoadBytes() As Byte
Dim FileNum As Integer
Dim FileSize As Long
Dim ArrayMax As Long
Dim AllStr As String
Dim TempStr As String
Dim TempPtr As Long
Dim I As Long, J As Long
Dim MaxI As Long
Dim Offset As Long
Dim StrOff As Long
Dim TimeLng As Long

FileNum = FreeFile

On Error GoTo ErrLoad
Open TxtFile.Text For Binary Access Read Lock Write As #FileNum
On Error GoTo 0

Screen.MousePointer = 13
Me.Caption = MeText + " 处理中……"
DoEvents
TimeLng = timeGetTime

FileSize = LOF(FileNum)

If FileSize <= 0 Then RText1.Text = "": Exit Sub
ArrayMax = FileSize - 1

ReDim LoadBytes(0 To ArrayMax)
Get #FileNum, , LoadBytes

Close #FileNum

MaxI = (ArrayMax + &HF) \ &H10 - 1
AllStr = Space(MaxI * 60 + IIf((ArrayMax And &HF) = &HF, 0, 10 + (ArrayMax And &HF) * 3))

TempPtr = StrPtr(AllStr)
For I = 0 To MaxI
StrOff = I * 60 * 2

TempStr = Hex$(I * &H10)
TempStr = String$(8 - Len(TempStr), "0") + TempStr + "h:"
Call CopyMemory(ByVal TempPtr + StrOff, ByVal StrPtr(TempStr), 20)

Offset = I * &H10

For J = 0 To &HF
If Offset + J > ArrayMax Then
Exit For

Else
TempStr = Hex$(LoadBytes(I * &H10 + J))
TempStr = " " + String$(2 - Len(TempStr), "0") + TempStr
Call CopyMemory(ByVal TempPtr + StrOff + (10 + J * 3) * 2, ByVal StrPtr(TempStr), 6)

End If

Next J

If J < &H10 Then
'
Else
TempStr = vbCrLf
Call CopyMemory(ByVal TempPtr + StrOff + 58 * 2, ByVal StrPtr(TempStr), 4)

End If

Next I

RText1.Text = AllStr

Screen.MousePointer = 0
TimeLng = timeGetTime - TimeLng
Me.Caption = MeText + " 处理时间:" + Format$(TimeLng, "##,###,###,##0") + "微秒"

Exit Sub

ErrLoad:
MsgBox Err.Description, vbCritical, Err.Number

End Sub
zyl910_up 2002-03-17
  • 打赏
  • 举报
回复
精确的是 939微秒!
zyl910 2002-03-17
  • 打赏
  • 举报
回复
我那个程序,打开一个24k的文件只需要一秒多!
zyl910 2002-03-17
  • 打赏
  • 举报
回复
看了没有:http://www.csdn.net/expert/topic/550/550567.xml?temp=.7191278

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧